Program to Check Leap Year - ( C Programs )
Example
#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
Enter a year: 2024
2024 is a leap year.
Explanation
A leap year is a year that is evenly divisible by 4 but not by 100. However, years that are evenly divisible by 100 are not leap years unless they are also evenly divisible by 400.
Therefore, in the given program, first, we take input from the user and check the condition year%4==0. If this condition is true, we check between the next condition i.e. year%100==0. If this is also true, we check the third condition as year%400==0, if this is also true, the entered year is a leap year, else it is not a leap year. If the second condition (year%100==0) is not true, the year is definitely a leap year.
Use
The program can be used to check whether a given year is a leap year or not.
Summary
The program checks whether a given year is a leap year or not, using the conditions mentioned above, and gives the output accordingly.