basics · intermediate · ~15 min
Pass structs by value and use `<math.h>`.
Compute the straight-line (Euclidean) distance between two 2-D points passed as structs.
The grader supplies this struct (do not redefine it):
typedef struct { double x, y; } point_t;
Implement double distance(point_t a, point_t b) returning the Euclidean distance between a and b. No main — the grader calls it.
Two point_t values passed by value, each with double fields x and y.
The distance sqrt((a.x-b.x)^2 + (a.y-b.y)^2) as a double. Use sqrt from <math.h>.
distance({0,0}, {3,4}) -> 5
distance({1,1}, {1,1}) -> 0
distance({1,2}, {4,6}) -> 5
0.Two point_t values a and b (each with double x, y).
The Euclidean distance between them as a double.
Use sqrt from <math.h>; do not redefine point_t.
#include <math.h>
double distance(point_t a, point_t b) {
/* TODO */
return 0.0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.