Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is:
Distance=(x2−x1)^2+(y2−y1)^2
Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0.
#include <bits/stdc++.h>
using namespace std;
// Function to calculate distance between the two points
float distance(int x1, int y1, int x2, int y2)
{
// Calculating distance
float pointDistance ;
pointDistance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
return pointDistance ;
}
// Getting print of the distance
int main()
{
cout << distance(1.0, 2.0, 1.0, 5.0);
return 0;
}
Comments
Leave a comment