Advertisement

 /* Write a C program to calculate the distance between the two points. */


#include<stdio.h>
#include<math.h>
int main( )
{
    int x1,x2,y1,y2;
    int x,y;
    float d;
    printf("Enter the coordinates of first point(x1,y1):");
    scanf("%d%d",&x1,&y1);
    printf("Enter the coordinates of the second point(x2,y2):");
    scanf("%d%d",&x2,&y2);
    x = (x2-x1);
    y = (y2-y1);
    d = sqrt((x*x)+(y*y));
    printf("Distance = %.2f\n",d);
    return 0;
}
  
Output:

Enter the coordinates of first point(x1,y1):3 7
Enter the coordinates of the second point(x2,y2):5 8
Distance = 2.236

Back

Post a Comment

0 Comments