basics · beginner · ~15 min
Provide a definition for a declared function.
Implement a declared function that returns the negation of its argument.
Implement int negate(int n) that returns -n. The linker matches this definition to its header declaration at build time. No main — the grader calls it.
A single int n.
Returns -n, as an int.
negate(5) -> -5
negate(-7) -> 7
negate(0) -> 0
A single int n.
-n, as an int.
int negate(int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.