C Program to check Leap Year

Share article on social media
In this article C program to check Leap Year, user input the year and program displays the year is leap year or not.
A leap year is a year that is divisible by 4, except for years that are divisible by 100 but not by 400. For example, 2000 was a leap year, but 1900 was not.
Leap Year Program in C
//leap year program in c
#include
int main()
{
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
if (year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
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;
}
This C program to check Leap Year, prompts the user to enter a year, and then uses a series of if statements to check whether the year is a leap year or not. The program first checks if the year is divisible by 4. If it is, it then checks if the year is divisible by 100. If it is, it checks if the year is divisible by 400. If the year is divisible by 4 but not by 100, or if it is divisible by 4, 100, and 400, it is considered to be a leap year. Otherwise, it is not a leap year.