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