basics · beginner · ~15 min

Max of three

Use `if/else` to compare values.

Challenge

Return the largest of three integers.

Task

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

Input

Three int arguments. Values may repeat and may be negative.

Output

The single largest int. If two or three are tied for the largest, return that value.

Example

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

Edge cases

  • All equal: return that value.
  • All negative: the one closest to zero is the largest.

Input format

Three int arguments a, b, c.

Output format

The largest of the three ints.

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.