include stdio h include math h struct coordinate

  • Slides: 7
Download presentation

#include <stdio. h> #include <math. h> struct coordinate { double x; double y; };

#include <stdio. h> #include <math. h> struct coordinate { double x; double y; }; double distance(struct coordinate A, struct coordinate B) { return sqrt(pow((A. x-B. x), 2)+pow((A. y-B. y), 2)); } struct coordinate midpoint(struct coordinate A, struct coordinate B) { struct coordinate M; M. x=(A. x+B. x)/2; M. y=(A. y+B. y)/2; return M; } void main() { struct coordinate P 1, P 2, mid; printf ("n enter the first coordinate "); scanf ("%lf%lf", &P 1. x, &P 1. y); printf ("n enter the second coordinate "); scanf ("%lf%lf", &P 2. x, &P 2. y); printf ("n d=%lf", distance(P 1, P 2)); mid=midpoint(P 1, P 2); printf ("n midpoint=(%0. 2 lf, %0. 2 lf)", mid. x, mid. y); }