ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Distance Between Points

Compute the straight-line distance between two points.

โจทย์

Compute the Euclidean distance between (x1, y1) and (x2, y2): the square root of (x2 − x1)² + (y2 − y1)².

Implement distance(x1, y1, x2, y2).

Input

x1: First point x. y1: First point y. x2: Second point x. y2: Second point y.

Output

Return the distance.

เงื่อนไข

-1,000,000 ≤ each coordinate ≤ 1,000,000

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
x1 = 0.0
x2 = 3.0
y1 = 0.0
y2 = 4.0

ผลลัพธ์ที่คาดหวัง:
expected = 5.0
อินพุต:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

ผลลัพธ์ที่คาดหวัง:
double expected = 5.0;
อินพุต:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

ผลลัพธ์ที่คาดหวัง:
double expected = 5.0;

คำอธิบาย

√(3² + 4²) = √25 = 5.

ตัวอย่างที่ 2
อินพุต:
x1 = 1.0
x2 = 1.0
y1 = 1.0
y2 = 1.0

ผลลัพธ์ที่คาดหวัง:
expected = 0.0
อินพุต:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

ผลลัพธ์ที่คาดหวัง:
double expected = 0.0;
อินพุต:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

ผลลัพธ์ที่คาดหวัง:
double expected = 0.0;

คำอธิบาย

Both points are the same, so the distance is 0.

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก