Einfach 0 gelöst 0% Erfolgsquote

Distance Between Points

Compute the straight-line distance between two points.

Problem

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.

Einschränkungen

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

Beispiele

Beispiel 1
Eingabe:
x1 = 0.0
x2 = 3.0
y1 = 0.0
y2 = 4.0

Erwartete Ausgabe:
expected = 5.0
Eingabe:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

Erwartete Ausgabe:
double expected = 5.0;
Eingabe:
double x1 = 0.0;
double x2 = 3.0;
double y1 = 0.0;
double y2 = 4.0;

Erwartete Ausgabe:
double expected = 5.0;

Erläuterung

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

Beispiel 2
Eingabe:
x1 = 1.0
x2 = 1.0
y1 = 1.0
y2 = 1.0

Erwartete Ausgabe:
expected = 0.0
Eingabe:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

Erwartete Ausgabe:
double expected = 0.0;
Eingabe:
double x1 = 1.0;
double x2 = 1.0;
double y1 = 1.0;
double y2 = 1.0;

Erwartete Ausgabe:
double expected = 0.0;

Erläuterung

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.