basics · beginner · ~15 min
Branch on a value's sign.
Reduce a number to its sign: negative, zero, or positive.
Implement int sign_of(long n) that returns -1 if n is negative, 0 if n is zero, and 1 if n is positive. No main — the grader calls it.
A single long n.
Returns -1, 0, or 1.
sign_of(-9) -> -1
sign_of(0) -> 0
sign_of(42) -> 1
A single long n.
-1, 0, or 1 for negative, zero, or positive n.
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.