Program to calculate the distance between two points

Problem Statement
Write a C program which reads the Cartesian co-ordinates of a pair of points and finds the distance between them.

#include<stdio.h> #include<math.h> int main() { int x1,x2,y1,y2,x,y,u; double dist; printf("enter coordinate of first point \n"); scanf("%d %d",&x1,&y1); printf("enter coordinate of secound point \n"); scanf("%d %d",&x2,&y2); x=(x1-x2)*(x1-x2); y=(y1-y2)*(y1-y2); printf("%d %d",x,y); u= (x+y); dist= sqrt(u); printf("the distance is %lf",dist); return 0; }

No comments:

Post a Comment