Leap Year Program in C
Here you will get an example code of Leap Year Program in C language using two various methods.
What is Leap Year?
A leap year is a calendar year that contains an additional day in the month of February So the year contains 366 days instead of 365 days.
In other words, the year of 366 days is known as leap year. Leap years repeat every 4 years.
leap year examples are:- 1996, 2000, 2004, 2008, and 2012.
While 1400, 1500, 1700 are century years, and not leap years.
How to find leap year using C programming?
To check whether the given year is a leap year or not, the user has to check the following rules.
⮞ Year should be divisible by 4.
⮞ Year should be divisible by 400 and not divisible by 100.
Leap Year Data Flow Diagram
How to Implement Leap Year Program in C?
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdio.h> int main() { int year; printf("Enter a Year :"); scanf("%d",&year); 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); return 0; } |
Output 1
Enter a year: 1700
1700 is not a Leap Year
Output 2
Enter a year: 2020
2020 is a Leap Year
Program to check Leap Year using nested if – else
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdio.h> int main() { int year; printf("Enter a year: "); scanf("%d", &year); if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) printf("%d is a Leap Year", year); else printf("%d is not a Leap Year", year); } else printf("%d is a Leap Year", year ); } else printf("%d is not a Leap Year", year); return 0; } |
Output 1 :
Enter a year: 2011
2011 is not a Leap Year
Output 2 :
Enter a year: 2000
2000 is a Leap Year
Check out our other C programming Examples