Write a C program to create a structure called point with XC and YC as data members. Find the distance between two points.
Use the following structure
struct point
{
int xc;
int yc;
};
Sample Input and Output:
Enter xc of point 1
-2
Enter yc of point 1
1
Enter xc of point 2
1
Enter yc of point 2
5
Distance between two points is 5.
Implementation of the above problem:
#include<stdio.h>
#include<math.h>
struct point
{
int xc;
int yc;
};
struct point c[2];
int main()
{
int i,n=2;
float dist;
for(i=0;i<n;i++)
{
printf("Enter xc of point %d\n",i+1);
scanf("%d",&c[i].xc);
printf("Enter yc of point %d\n",i+1);
scanf("%d",&c[i].yc);
}
dist=sqrt(pow(((c[1].xc)-(c[0].xc)),2)+pow(((c[1].yc)-(c[0].yc)),2));
printf("Distance between two points is %0.2f",dist);
return 0;
}
Thanks
Mukesh Rajput
Post A Comment:
0 comments: