#include <stdio.h>
#include <math.h> // for fabs
// Function that returns the distance between two decimal numbers
double distanceBetween(double a, double b) {
// The distance is the absolute value of the difference
return fabs(a - b);
}
int main() {
// Test values
double x1 = 100, y1 = 45;
double x2 = 100, y2 = -15;
double x3 = -100, y3 = -125;
double x4 = -600, y4 = 100;
// Print results
printf("Distance between %.2f and %.2f = %.2f\n", x1, y1, distanceBetween(x1, y1));
printf("Distance between %.2f and %.2f = %.2f\n", x2, y2, distanceBetween(x2, y2));
printf("Distance between %.2f and %.2f = %.2f\n", x3, y3, distanceBetween(x3, y3));
printf("Distance between %.2f and %.2f = %.2f\n", x4, y4, distanceBetween(x4, y4));
return 0;
}
/*
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
*/