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