1
0

08_pointdist.c 398 B

1234567891011121314151617181920212223242526
  1. #include <math.h>
  2. #include <stdio.h>
  3. struct Point
  4. {
  5. int x;
  6. int y;
  7. };
  8. double dist(struct Point *a, struct Point *b)
  9. {
  10. return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2));
  11. }
  12. int main()
  13. {
  14. struct Point p1;
  15. struct Point p2;
  16. p1.x = 1;
  17. p1.y = 0;
  18. p2.x = 0;
  19. p2.y = 1;
  20. printf("Distance between points [%d, %d] and [%d, %d] is %f\n", p1.x, p1.y,
  21. p2.x, p2.y, dist(&p1, &p2));
  22. return 0;
  23. }