basics · beginner · ~15 min

Maximum of three

Combine comparisons with if/else.

Challenge

Return the largest of three integers.

Task

Implement int max3(int a, int b, int c) that returns the largest of the three values. No main — the grader calls it.

Input

Three ints a, b, and c.

Output

Returns the maximum of the three, as an int.

Example

max3(3, 1, 2)      ->   3
max3(1, 5, 2)      ->   5
max3(1, 2, 9)      ->   9
max3(-3, -1, -2)   ->   -1

Edge cases

  • All-negative inputs return the largest (closest to zero).

Input format

Three ints a, b, and c.

Output format

The largest of the three, as an int.

Starter code

int max3(int a, int b, int c) {
    /* TODO */
    return 0;
}

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