basics · beginner · ~15 min

Larger of two

Produce a function the compiler accepts and links.

Challenge

Write a clean, warning-free function the compiler can turn into an object file.

Task

Implement int max2(int a, int b) that returns the larger of the two values (return either when they are equal). No main — the grader calls it.

Input

Two ints a and b.

Output

Returns the larger value, as an int.

Example

max2(3, 7)     ->   7
max2(9, 2)     ->   9
max2(5, 5)     ->   5
max2(-1, -4)   ->   -1

Edge cases

  • Equal inputs return that shared value.
  • Negative values compare normally.

Input format

Two ints a and b.

Output format

The larger of a and b, as an int.

Starter code

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

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