Problema
Ver traduçãoA 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.
Restrições
1 ≤ year ≤ 9999.
Exemplos
Entrada:
year = 2024
Saída esperada:
expected = True
Entrada:
long long year = 2024;
Saída esperada:
bool expected = true;
Entrada:
long year = 2024;
Saída esperada:
bool expected = true;
Explicação
2024 is divisible by 4 and not by 100.
Entrada:
year = 2100
Saída esperada:
expected = False
Entrada:
long long year = 2100;
Saída esperada:
bool expected = false;
Entrada:
long year = 2100;
Saída esperada:
bool expected = false;
Explicação
2100 is divisible by 100 but not by 400, so the century exception applies.
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.