Simvik

The larger of two

Choose between two values with an if statement. An easy embedded C problem (Decisions and loops), run and graded in the browser.

easy · Decisions and loops · if

Return whichever of a and b is larger. If they are equal, return either.

Starter code

int max2(int a, int b) {
  return a;
}

Example tests

The second is larger

printf("%d\n", max2(3, 9));

Expected output:

9

The first is larger

printf("%d\n", max2(5, -5));

Expected output:

5

Learn it first

  • Decisions and loops · Choosing with if and switch, repeating with while and for, and the loop that never ends.

More Decisions and loops problems