Q.Write a program to check if the year entered by the user is a leap year or not.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Concept understanding — Leap Year Determination
Leap Year Determination
You already know a year is 365 days. But the Earth actually takes about 365.2422 days to orbit the Sun — a little more than 365 days. That extra 0.2422 day (roughly 6 hours) adds up. After 4 years, it becomes almost a full day. So we add an extra day every 4 years to keep the calendar aligned with the seasons. That extra day is February 29, and that year is a leap year.
But if we added a leap day every 4 years without exception, we'd overshoot. Because 0.2422 × 4 = 0.9688 day, not exactly 1 day. So every 4 years we add a bit too much — about 0.0312 day too much. Over centuries, that error accumulates. To fix it, we skip some leap years.
The precise rule
A year is a leap year if:
- It is divisible by 4, and
- If it is divisible by 100, it must also be divisible by 400.
In other words:
Let's break that down.
Step 1: Every year divisible by 4 is a leap year — unless it's a century year.
Step 2: Century years (like 1900, 2000, 2100) are leap years only if they are divisible by 400.
So 2000 was a leap year (divisible by 400). 1900 was not (divisible by 100 but not by 400). 2100 will not be a leap year.
A common mistake is to think every year divisible by 4 is a leap year. That's almost true, but the century-year exception is crucial. 1900 was divisible by 4, yet it was not a leap year.
Why this works
The Gregorian calendar (the one we use) was designed to keep the average year length very close to 365.2422 days. The rule gives an average year length of:
…
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.