basics · beginner · ~15 min

Square a number

Use an arithmetic expression in a return.

Challenge

Implement int square(int n) returning n*n.

Starter code

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

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