In this program, You learn about leap year in detail in below then learn program to check leap year in C using if-else statement.
Leap Year
A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400. Since 1900 is divisible by 4 and is also a century year (ending with 00), it has been divisible by 400 for a leap year. Since it's not divisible by 400, 1900 is not a leap year.Check leap year in C
Program:
#include<stdio.h>
int main()
{
int year;
printf("\n Enter a year:");
scanf("%d",&year);
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
{
if(year%4==0)
{
printf("%d is a leap year",year);
}
else
{
printf("%d is not a leap year",year);
}
}
return 0;
}
For example, if the user enters 1900 then the output will be:
Enter a year:1900
1900 is not a leap year
You have any problem in the above program to check leap year in C using the if-else statement. Do not hesitate and write your problem in the comment box. I will support your problem.