Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,844 questions

55,671 answers

573 users

How to calculates the distance between two decimal numbers (absolute difference) in Pascal

1 Answer

0 votes
program DistanceBetweenNumbers;

uses
  Math;  // for Abs()

// Function that returns the distance between two decimal numbers
function DistanceBetween(a, b: Double): Double;
begin
  // The distance is the absolute value of the difference
  DistanceBetween := Abs(a - b);
end;

var
  x1, y1: Double;
  x2, y2: Double;
  x3, y3: Double;
  x4, y4: Double;

begin
  // Test values
  x1 := 100;   y1 := 45;
  x2 := 100;   y2 := -15;
  x3 := -100;  y3 := -125;
  x4 := -600;  y4 := 100;

  // Print results
  WriteLn('Distance between ', x1:0:2, ' and ', y1:0:2, ' = ', DistanceBetween(x1, y1):0:2);
  WriteLn('Distance between ', x2:0:2, ' and ', y2:0:2, ' = ', DistanceBetween(x2, y2):0:2);
  WriteLn('Distance between ', x3:0:2, ' and ', y3:0:2, ' = ', DistanceBetween(x3, y3):0:2);
  WriteLn('Distance between ', x4:0:2, ' and ', y4:0:2, ' = ', DistanceBetween(x4, y4):0:2);
end.



{
run:

Distance between 100.00 and 45.00 = 55.00
Distance between 100.00 and -15.00 = 115.00
Distance between -100.00 and -125.00 = 25.00
Distance between -600.00 and 100.00 = 700.00

}

 



answered Jun 28 by avibootz

Related questions

...