#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void distance (void); // with void
int main()
{
distance();
return 0;
}
void distance (void)
{
double x1, x2, y1, y2, d;
cout << "Enter value for x1: " << endl;
cin >> x1;
cout << "Enter value for y1: " << endl;
cin >> y1;
cout << "Enter value for x2: " << endl;
cin >> x2;
cout << "Enter value for y2: " << endl;
cin >> y2;
d = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));
cout << "The distance between the two points are: " << "d = " << d << endl;
}
/*
int main()
{
double distance (double x1, double y1, double x2, double y2); // without void
double x1, x2, y1, y2;
cout << "Enter value for x1: " << endl;
cin >> x1;
cout << "Enter value for y1: " << endl;
cin >> y1;
cout << "Enter value for x2: " << endl;
cin >> x2;
cout << "Enter value for y2: " << endl;
cin >> y2;
cout << "The distance between the two points are: " << distance (x1, y1, x2, y2) << endl;
}
double distance (double x1, double y1, double x2, double y2)
{
return sqrt (((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));
}
*/
No comments:
Post a Comment