Facile 0 résolus 0 % de réussite

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.

Contraintes

1 ≤ year ≤ 9999.

Exemples

Exemple 1
Entrée :
year = 2024

Sortie attendue :
expected = True
Entrée :
long long year = 2024;

Sortie attendue :
bool expected = true;
Entrée :
long year = 2024;

Sortie attendue :
bool expected = true;

Explication

2024 is divisible by 4 and not by 100.

Exemple 2
Entrée :
year = 2100

Sortie attendue :
expected = False
Entrée :
long long year = 2100;

Sortie attendue :
bool expected = false;
Entrée :
long year = 2100;

Sortie attendue :
bool expected = false;

Explication

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

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.