๐Ÿ”€โšก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>
2
3int main() {
4 int year;
5
6 printf("Enter a year: ");
7 scanf("%d", &year);
8
9 // Check leap year conditions
10 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รท400Leap?
2024YesNoNoโœ“ Leap
1900YesYesNoโœ— Not Leap
2000YesYesYesโœ“ Leap
2023NoNoNoโœ— 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