This program checks whether the input year is leap year or not.
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 year
If a year is divisible by 4 and 100 but not divisible by 400 then it is not a leap year
Lets write this logic in a C Program. To understand this program you should have the knowledge of following C Programming topic:
#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
Check out these related C Programs:
Leave a Reply