#include<iostream.h>
#include<math.h>
#include<conio.h>
float distance(float,float,float,float);
float distance(float,float,float,float,float,float);
main()
{
clrscr();
float x1;
float x2;
float y1;
float y2;
float distance_1;
cout<<"\n ********* 2D Distance ********"<<endl;
cout<<"\n Enter the value of the first point P1 :"<<endl;
cout<<"\t\t x_1 = ";
cin>>x1;
cout<<"\t\t y_1 = ";
cin>>y1;
cout<<"\n Enter the value of the second point P2 :"<<endl;
cout<<"\t\t x_2 = ";
cin>>x2;
cout<<"\t\t y_2 = ";
cin>>y2;
float x_1;
float x_2;
float y_1;
float y_2;
float z_1;
float z_2;
float distance_2;
cout<<"\n\n ********* 3D Distance ********"<<endl;
cout<<"\n Enter the value of the first point P1 :"<<endl;
cout<<"\t\t x_1 = ";
cin>>x_1;
cout<<"\t\t y_1 = ";
cin>>y_1;
cout<<"\t\t z_1 = ";
cin>>z_1;
cout<<"\n Enter the value of the second point P2 :"<<endl;
cout<<"\t\t x_2 = ";
cin>>x_2;
cout<<"\t\t y_2 = ";
cin>>y_2;
cout<<"\t\t z_2 = ";
cin>>z_2;
getch();
clrscr();
cout<<"\n ********* 2D Distance ********"<<endl;
cout<<"\n The values of the points P1 & P2 are :"<<endl;
cout<<"\t\tP1 (x1,y1) = P1 ("<<x1<<","<<y1<<")"<<endl;
cout<<"\t\t P2 (x2,y2) = P2 ("<<x2<<","<<y2<<")"<<endl;
cout<<"\n Distance b/w P1 & P2 is :"<<endl;
distance_1=distance(x1,y1,x2,y2);
cout<<"\t\t ³P1P2³ = "<<distance_1<<endl;
cout<<"\n\n ********* 3D Distance ********"<<endl;
cout<<"\n The values of the points P1 & P2 are :"<<endl;
cout<<"\t\t P1 (x1,y1,z1) = P1 ("<<x_1<<","<<y_1<<","<<z_1<<")"<<endl;
cout<<"\t\t P2 (x2,y2,z2) = P2 ("<<x_2<<","<<y_2<<","<<z_2<<")"<<endl;
cout<<"\n Distance b/w P1 & P2 is :"<<endl;
distance_2=distance(x_1,y_1,z_1,x_2,y_2,z_2);
cout<<"\t\t ³P1P2³ = "<<distance_2<<endl;
getch();
return 0;
}
/*************************************************************************///------------------- distance(float,float,float,float) ---------------///*************************************************************************/float distance(float x_1,float y_1,float x_2,float y_2)
{
float distance=0;
distance=sqrt(pow((x_2-x_1),2)+pow((y_2-y_1),2));
return distance;
}
/*************************************************************************///------------- distance(float,float,float,float,float,float) ---------///*************************************************************************/float distance(float x_1,float y_1,float z_1,float x_2,float y_2,float z_2)
{
float distance=0;
distance=sqrt(pow((x_2-x_1),2)+pow((y_2-y_1),2)+pow((z_2-z_1),2));
return distance;
}