PROGRAM
write a program to read coordinates of two points and calculates the distance between them as per following formula:d=sqrt(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
int main()
{
system("cls");
double distance,x1,x2,y1,y2;
cout<<"Enter coordinates(xy) of point1:";
cin>>x1>>y1;
cout<<"Enter coordinates(xy) of point2:";
cin>>x2>>y2;
distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<"The distance between("<<x1<<","<<y1<<")and("<<x2<<","<<y2<<")is:"<<distance<<endl;;
return 0;
}
========================================================================
OUTPUT:
Enter coordinates(xy) of point1:5 6.5
Enter coordinates(xy) of point2:2 4.1
The distance between(5,6.5)and(2,4.1)is:3.841875
========================================================================
No comments:
Post a Comment