Slyfoxx724

extra4.c

Dec 7th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. 1 #include <stdio.h>
  2. 2 #include <math.h>
  3. 3
  4. 4 struct point
  5. 5 {
  6. 6 float x;
  7. 7 float y;
  8. 8 };
  9. 9
  10. 10 float distance(struct point, struct point);
  11. 11 void enter_a_point(struct point *);
  12. 12
  13. 13 int main(void)
  14. 14 {
  15. 15 struct point pt1, pt2;
  16. 16
  17. 17 enter_a_point(&pt1);
  18. 18 enter_a_point(&pt2);
  19. 19 printf("Distance between the points = %.2f\n", distance(pt1, pt2));
  20. 20
  21. 21 return 0;
  22. 22 }
  23. 23
  24. 24 float distance(struct point p1, struct point p2)
  25. 25 {
  26. 26 return sqrt( pow(p2.x-p1.x, 2) + pow(p2.y-p1.y, 2));
  27. 27 }
  28. 28
  29. 29 void enter_a_point(struct point *p)
  30. 30 {
  31. 31 printf("\nEnter an X coordinate: ");
  32. 32 scanf("%f", &p->x);
  33. 33
  34. 34 printf("\nEnter a Y coordinate: ");
  35. 35 scanf("%f", &p->y);
  36. 36 }
Add Comment
Please, Sign In to add comment