Leap Year Challenge Exercise

luhan
انضم:
2024-07-25 15:54:47

Image preview

In your preferred language, write a program that works out whether a given year is a leap year. A normal year has 365 days, and leap years have 366, with an extra day in February.

This is how to work out whether a particular year is a leap year:

*A year is a leap year if it is evenly divisible by **4** ;*

***except** if that year is also evenly divisible by **100**;*

***unless** that year is also evenly divisible by **400**.*

For more context,

Is the year 2400 a leap year?:

2400 ÷ 4 = 600 (Leap)

2400 ÷ 100 = 24 (Not Leap)

2400 ÷ 400 = 6 (Leap!)

So the year 2400 is a leap year.

But the year 2100 is not a leap year because:

2100 ÷ 4 = 525 (Leap)

2100 ÷ 100 = 21 (Not Leap)

2100 ÷ 400 = 5.25 (Not Leap)

Facebook X (Twitter) Instagram LinkedIn Telegram WhatsApp