# Leap Year Program in C

Here we will write the leap year program in C language. We can use if-else, nested if-else, or switch case statement for this problem.

A year is called leap year if the year is divisible by four, except for the years which are divisible by 100 but not divisible by 400. Therefore, the year 2000 was a leap year, but the years 1700, 1800, and 1900 were not.

The complete list of leap years in the first half of the 21st century is 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, and 2048. Prerequisites for leap year program:- If-else statement in C, Programs on if-else in C, Switch case in C programming, Programs on switch case in C

## Leap Year Program in C Using if-else statement

``````#include<stdio.h>
int main()
{
int year;

printf("Enter Year: ");
scanf("%d",&year);

if(( year%4==0) && ( (year%400==0) || (year%100!=0) ) )
printf("%d is a leap year.",year);
else
printf("%d is not a leap year.",year);

return 0;
}``````

Output:-

Enter Year: 2025
2025 is not a leap year.

Enter Year: 2000
2000 is a leap year.

In this program, all conditions are written within the if condition, so it may look likes complicated for you. In the below program, the nested-if statement is used for the same problem. Now, you may understand the logic simply.

## Check Leap Year Using nested if-else

``````#include<stdio.h>
int main()
{
int year;

printf("Enter Year:");
scanf("%d",&year);

if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
printf("%d is leap year.",year);

else
printf("%d is not leap year.",year);
}

else
printf("%d is leap year.",year);
}

else
printf("%d is not leap year.",year);

return 0;
}``````

## Check Leap Year Using a switch case statement

``````#include<stdio.h>
int main()
{
int year, remainder;

printf("Enter Year: ");
scanf("%d",&year);

remainder=((year%4==0)&&((year%400==0)||(year%100!=0)));

switch(remainder)
{

case 1:
printf("Leap Year.");
break;

case 0:
printf("Not Leap Year.");
break;

default:
printf("Invalid.");
break;

}

return 0;
}``````

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar C program examples