Answer to Question #159952 in C++ for Jeswin

Question #159952

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.


1
Expert's answer
2021-01-30T06:33:51-0500
#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; 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog