WAP- Distance between two points (x1,y1) and (x2,y2) is governed by the following formula D=sqrt((x2-x1)^2 + (y2-y1)^2). Write a program to computer D given the coordinates of the points.

//E Balagurusamy, Programming In ANSI C,4E
//Exercise 1.11, page 22

#include <stdio.h>

//point 1
#define x1 5
#define y1 2

//point 2
#define x2 14
#define y2 7

int main(void)
{int term1, term2,D;
printf("\n\n");

term1=(x2-x1)*(x2-x1);
term2=(y2-y1)*(y2-y1);

D=sqrt(term1+term2);

printf("The distance between points (%d,%d) and (%d,%d) is %d",x1,y1, x2,y2, D);

printf("\n\n");
return 0;
}

Comments