Simvik

Even or odd

Produce a yes-or-no answer as 1 or 0. An easy embedded C problem (Variables and operators), run and graded in the browser.

easy · Variables and operators · comparison · remainder

In C a comparison such as a == b is itself a value. It is 1 when true and 0 when false.

Return 1 if n is even and 0 if it is odd.

Starter code

int is_even(int n) {
  return 0;
}

Example tests

An even number

printf("%d\n", is_even(4));

Expected output:

1

An odd number

printf("%d\n", is_even(7));

Expected output:

0

Learn it first

More Variables and operators problems