132k views
5 votes
Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to pointsDistance. The calculation is: Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is 3.0.

User Martinr
by
5.7k points

2 Answers

3 votes

Answer:

pointsDistance = sqrt (pow(x2 - x1,2.0) + pow(y2 - y1,2.0));

Explanation:

User Abanmitra
by
5.4k points
5 votes

Answer:

void distance(int x1, int x2, int y1, int y2){

pointsDistance = sqrt((x2-x1)^(2) + (y2-y1)^(2));

}

Explanation:

Suppose we have two points:


A = (x_(1), y_(1))


B = (x_(2), y_(2)

The distance between these points is:


D = \sqrt{(x_(2) - x_(1))^(2) + (y_(2) - y_(1))^(2)}

So, for points (1.0, 2.0) and (1.0, 5.0)


D = \sqrt{(1 - 1)^(2) + (5 - 2)^(2)} = √(9) = 3

I suppose this questions asks me to write a code, since i have to attribute the result to pointsDistance. I am going to write a C code for this, and you have to include the math.h library.

void distance(int x1, int x2, int y1, int y2){

pointsDistance = sqrt((x2-x1)^(2) + (y2-y1)^(2));

}

User KevinHJ
by
5.5k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.