Simvik

Leap year

Turn a rule with exceptions into a logical expression. An easy embedded C problem (Functions), run and graded in the browser.

easy · Functions · bool · logic

A year is a leap year if it is divisible by 4, except that years divisible by 100 are not, unless they are also divisible by 400. So 2024 and 2000 are leap years, and 1900 is not.

Return true if year is a leap year. || means "or", and != means "is not equal to".

Starter code

bool is_leap_year(int year) {
  return year % 4 == 0;
}

Example tests

Divisible by four

printf("%d\n", is_leap_year(2024));

Expected output:

1

An ordinary year

printf("%d\n", is_leap_year(2023));

Expected output:

0

Learn it first

  • Functions · Splitting a program into named pieces, passing values in and getting results back.

More Functions problems