basics · intermediate · ~15 min

Distance between points

Pass structs by value and use `<math.h>`.

Challenge

Given the struct

typedef struct { double x, y; } point_t;

implement double distance(point_t a, point_t b) returning the Euclidean distance.

The struct is supplied by the grader — do not redefine it.

Starter code

#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.