basics · beginner · ~15 min
Use an arithmetic expression in a return.
Return the square of an integer.
Implement int square(int n) that returns n * n. No main — the grader calls it.
A single int n.
Returns n squared, as an int.
square(4) -> 16
square(-3) -> 9
square(0) -> 0
A single int n.
n * n, as an int.
int square(int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.