Tous les défis
Facile 0 résolus 0 % de réussite

Days in a Month

Return how many days a month has, including leap years.

Problème

Return the number of days in month of year in the Gregorian calendar. February has 29 days in a leap year: years divisible by 4, except those divisible by 100 unless also divisible by 400. A helper function is_leap(year) keeps the code tidy.

Implement days_in_month(year, month).

Input

year: The year. month: The month, 1 (January) to 12 (December).

Output

Return the number of days.

Contraintes

1 ≤ year ≤ 9,999; 1 ≤ month ≤ 12

Exemples

Exemple 1
Entrée :
year = 2024
month = 2

Sortie attendue :
expected = 29
Entrée :
long long year = 2024;
long long month = 2;

Sortie attendue :
long long expected = 29;
Entrée :
long year = 2024;
long month = 2;

Sortie attendue :
long expected = 29;

Explication

2024 is divisible by 4 and not by 100, so it is a leap year: 29 days.

Exemple 2
Entrée :
year = 1900
month = 2

Sortie attendue :
expected = 28
Entrée :
long long year = 1900;
long long month = 2;

Sortie attendue :
long long expected = 28;
Entrée :
long year = 1900;
long month = 2;

Sortie attendue :
long expected = 28;

Explication

1900 is divisible by 100 but not 400, so it is not a leap year: 28 days.

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.