Skip to content

Instantly share code, notes, and snippets.

@oykelrae
Last active December 9, 2019 22:57
Show Gist options
  • Save oykelrae/5cc534d3955b5867f568e5fd1898d14f to your computer and use it in GitHub Desktop.
Save oykelrae/5cc534d3955b5867f568e5fd1898d14f to your computer and use it in GitHub Desktop.
<math.h> Distance between two points
#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;
}
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