Last active
December 9, 2019 22:57
-
-
Save oykelrae/5cc534d3955b5867f568e5fd1898d14f to your computer and use it in GitHub Desktop.
<math.h> Distance between two points
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int main() { | |
double x1, x2, y1, y2, dist; | |
printf("Enter the coordinates of a point A (x1 and y1): "); | |
scanf("%lf %lf", &x1, &y1); | |
printf("Enter the coordinates of a point B (x2 and y2): "); | |
scanf("%lf %lf", &x2, &y2); | |
dist = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); | |
printf("Distance between points A and B is %.2lf\n\n", dist); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enter the coordinates of a point A (x1 and y1): -2 -3 | |
Enter the coordinates of a point B (x2 and y2): 4 -1 | |
Distance between points A and B is 6.32 | |
Program ended with exit code: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment