Programming Languages
Welcome to coding world
C Program to check Leap Year
Example: Program to check Leap Year
You can check whether a year is leap or not by using
this mathematical logic:
Leap Year:
If a year is divisible by 4, 100 and 400 then it is a leap year.If a year is divisible by 4 but not divisible by 100 then it is a leap year
Not a Leap Year:
If a year is not divisible by 4 then it is not a leap yearIf a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year
Let’s write this logic in a C Program. To understand
this program you should have the knowledge of following C programming topic:
C Programming If..else, Nested if..else
#include <stdio.h>
int main()
{
int y;
printf("Enter
year: ");
scanf("%d",&y);
if(y % 4 ==
0)
{
//Nested if else
if( y %
100 == 0)
{
if
( y % 400 == 0)
printf("%d is a Leap Year", y);
else
printf("%d is not a Leap Year", y);
}
else
printf("%d is a Leap Year", y );
}
else
printf("%d
is not a Leap Year", y);
return 0;
}
Output:
Enter year: 1991
1991 is not a Leap Year