This is the tutorial on the C program to check Leap year. In order to understand the program better, you need to have knowledge of the following topics in C.
A leap year comes after every 4 years and has 366 days that year instead of 365 days. In the leap year, an additional day is added to the February month has 29 days instead of 28 days.
Now let us understand through mathematical logic,
- If a year is divisible by 4 then it is leap year.
- If a year is divisible by 400 and not divisible by 100 then it is also a leap year.
- Example: 2000, 2004, 2008, etc are the leap years.
C Program to Check whether a year is a leap year or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<stdio.h> #include<conio.h> void main() { int year; printf("Enter a year: "); scanf("%d", &year); //checking all the condition if((year%4 == 0 && year%100 != 0 ) || (year%400 == 0)) { printf("%d is a LEAP YEAR", year); } else { printf("%d is NOT a LEAP YEAR", year); } getch(); } |
Output:
//RUN 1
Enter a year: 1996
1996 is a LEAP YEAR
//RUN 2
Enter a year: 2005
2005 is NOT a LEAP YEAR