Wednesday 18 June 2014

WRITE A C++ PROGRAM TO READ COORDINATES OF TWO POINTS AND CALCULATE DISTANCE B/W THEM BY GIVEN FORMULA.



Program to Read coordinates of two Points and Calculate Distance b/w the by given Formula.



GIVEN FORMULA : sqrt((x1-x2)^2 + (y1+y2)^2)


PROGRAM

#include<iostream.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double distance,x1,y1,x2,y2;
cout<<"Enter the coordinates of point1: ";
cin>>x1>>y1;
cout<<"Enter the coordinates of point2:";
cin>>x2>>y2;

distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
cout<<"The distance is given by:";
cout<<distance;
return 0;
}



OUTPUT:

Enter  the coordinates of point1:5 6.5
Enter the coordinates of point2: 2 4.1
The distance is given by: 3.841 


No comments:

Post a Comment