basics · beginner · ~15 min

Sign of a number

Branch on a value's sign.

Challenge

Implement int sign_of(long n) returning -1, 0, or 1 for negative, zero, and positive n.

Starter code

int sign_of(long n) {
    /* TODO */
    return 0;
}

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