๐โกBeginner
Check Leap Year
Determine if year is leap year
A leap year has 366 days (February has 29 days). The rules are:
โข Divisible by 4 AND not divisible by 100, OR
โข Divisible by 400
๐ Leap Year Rules
โDivisible by 400 โ Leap Year (e.g., 2000)
โDivisible by 100 but not 400 โ Not Leap (e.g., 1900)
โDivisible by 4 โ Leap Year (e.g., 2024)
C Program to Check Leap Year
leap_year.c
C
1#include <stdio.h>23int main() {4 int year;5 6 printf("Enter a year: ");7 scanf("%d", &year);8 9 // Check leap year conditions10 if ((year % 4 == 0 && year % 100 != 0) || 11 (year % 400 == 0)) {12 printf("%d is a Leap Year\n", year);13 } else {14 printf("%d is Not a Leap Year\n", year);15 }16 17 return 0;18}Output
Enter a year: 2024
2024 is a Leap Year
Examples
| Year | รท4 | รท100 | รท400 | Leap? |
|---|---|---|---|---|
| 2024 | Yes | No | No | โ Leap |
| 1900 | Yes | Yes | No | โ Not Leap |
| 2000 | Yes | Yes | Yes | โ Leap |
| 2023 | No | No | No | โ Not Leap |
Step-by-Step Execution:
1
Input: 2024
year = 2024
2
Check year % 400
2024 % 400 = 24 โ 0, FALSE
3
Check year % 4
2024 % 4 = 0, TRUE
4
Check year % 100
2024 % 100 = 24 โ 0, TRUE (not divisible)
5
Result
(TRUE && TRUE) = TRUE โ Leap Year!
๐ Key Takeaways
โDivisible by 400 = always leap
โDivisible by 100 (not 400) = not leap
โDivisible by 4 only = leap
โUse parentheses for complex conditions
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials