Previous Next
0 / 18
Module DEMO-32-90DEMO-C-32

Euclidean Distance

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a function float distance(float x1, float y1, float x2, float y2) that returns the Euclidean distance between two points (x1, y1) and (x2, y2).

Formula: sqrt((x2-x1)^2 + (y2-y1)^2).

Constraints

Standard float.

Input Format

Four floats.

Output Format

Distance value.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
0.0 0.0 3.0 4.0
5.000000
Distance from origin to (3,4) is 5.
Sample #2
Public sample
-1.0 -1.0 -1.0 -1.0
0.000000
Same point.
Sample #3
Public sample
0.0 0.0 0.0 10.0
10.000000
Vertical line len 10.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings