Facile 0 risolte 0% di accettazione

Leap Year

Check whether a year follows the Gregorian leap-year rule.

A year divisible by 4 is a leap year unless it is also divisible by 100. Years divisible by 400 are leap years despite that exception. Apply this arithmetic rule to every allowed input year.

Implement leap_year(year).

Input

year: The year to check.

Output

Return true for a leap year and false otherwise.

Vincoli

1 ≤ year ≤ 9999.

Esempi

Esempio 1
Input:
year = 2024

Output atteso:
expected = True
Input:
long long year = 2024;

Output atteso:
bool expected = true;
Input:
long year = 2024;

Output atteso:
bool expected = true;

Spiegazione

2024 is divisible by 4 and not by 100.

Esempio 2
Input:
year = 2100

Output atteso:
expected = False
Input:
long long year = 2100;

Output atteso:
bool expected = false;
Input:
long year = 2100;

Output atteso:
bool expected = false;

Spiegazione

2100 is divisible by 100 but not by 400, so the century exception applies.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.