Program 6: Accept the x and y coordinates of two points and compute the distance between the two points. #include<stdio.h> ...

C Program to find distance between two coordinates





Program 6: Accept the x and y coordinates of two points and compute the distance between the two points.

#include<stdio.h>
#include<math.h>
int main()
{
float x1,x2,y1,y2,compute,distance;
printf("\nEnter values of x1 and y1:");
scanf("%d%d",&x1,&y1);
printf("\nEnter values of x2 and y2:");
scanf("%d%d",&x2,&y2);
compute=((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
distance=sqrt(compute);
printf("\nDistance=%f",distance);
}

 Output
[root@localhost ~]# cd ~/Desktop
[root@localhost Desktop]# gcc  distance.c
[root@localhost Desktop]# ./a.out
Enter values of x1 and y1:5 4
Enter values of x2 and y2:9 8
distance=5.656854

0 coment�rios:

HTML5 CSS3 TUTORIAL FOR BEGINNERS