A leap year has 366 days (February has 29). In the Gregorian calendar, leap years follow the 4 / 100 / 400 rule.
Remember
year is leap ⇔
(year % 4 == 0 AND year % 100 != 0)
OR
(year % 400 == 0)
Examples:
2024 → divisible by 4, not by 100 → leap
1900 → divisible by 100, not by 400 → not leap
2000 → divisible by 400 → leap
2023 → not divisible by 4 → not leap
Year
Why
Leap?
2024
% 4 == 0, not a century
Yes
2000
% 400 == 0
Yes
1900
century, not % 400
No
2023
not % 4
No
Approach
How to Check a Leap Year in C
Four clear steps — then write it as one expression or nested ifs.
If the year is not divisible by 4, it is not a leap year.
If it is divisible by 4 but not by 100, it is a leap year.
If it is divisible by 100, it must also be divisible by 400.
Otherwise it is not a leap year.
Method
Idea
Time
Best for
Boolean expression
One-line 4/100/400 predicate
O(1)
Interviews, short code
Nested if
Same rule, branched for reading aloud
O(1)
Explaining each condition
Pseudocode
Pseudocode
function IsLeapYear(year):
if year mod 400 == 0:
return true
if year mod 100 == 0:
return false
if year mod 4 == 0:
return true
return false
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Rule
(%4 && !%100) || %400
February
29 days in a leap year
Century leap
Only if divisible by 400
Classic yes
2024, 2000
Classic no
1900, 2023
Standard C
No built-in leap helper — write the rule
Try it
Live Preview
Enter any year to see each divisibility check and the final verdict.
Whole years from 1 to 9999. Tap a chip or type a year.
Result
year = 2024
2024 % 4 = 0
2024 % 100 = 24
2024 % 400 = 24
Divisible by 4 and not a century year
Verdict: LEAP YEAR
Trace
Worked Walkthrough — year = 2000 and 1900
Century years look similar until you apply the % 400 test.
Calculation
year = 2000
2000 % 400 = 0 → leap ✓
year = 1900
1900 % 400 = 300 ≠ 0
1900 % 100 = 0 → century, not leap ✗
year = 2024
2024 % 4 = 0
2024 % 100 ≠ 0 → leap ✓
Code
C Programs
Start with a one-line boolean expression. Use nested ifs when you want to explain each rule out loud.
Example 1 — Boolean Expression
Encode the Gregorian rule in a single return statement.
C
#include <stdio.h>
#include <stdbool.h>
bool is_leap_year(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int main(void)
{
int year = 2024;
if (is_leap_year(year))
{
printf("%d is a leap year\\n", year);
}
else
{
printf("%d is not a leap year\\n", year);
}
return 0;
}
Output
2024 is a leap year
How It Works
year % 4 == 0 is the basic every-4-years test.
year % 100 != 0 excludes most century years.
year % 400 == 0 brings century leaps like 2000 back in.
The || joins both paths into one boolean result.
For 2024: divisible by 4, not by 100 → leap.
Example 2 — Nested If
Same logic, written as branches so each rule is easy to narrate in an interview.