data-structures · beginner · ~15 min

Manhattan distance between points

Declare a struct and access its members.

Challenge

Define struct Point { int x, y; }; and implement int manhattan(struct Point a, struct Point b) returning |a.x-b.x| + |a.y-b.y|.

Starter code

struct Point { int x, y; };

int manhattan(struct Point a, struct Point b) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.