6.4 C
New York
Friday, March 1, 2024

# C Program to Check Leap Year

### What is a Leap Year?

A year exactly divisible by 4 is known as leap year except for centurial years. A centurial year will be a leap year if it is exactly divisible by 400, for example, the year 1700 is not a leap year whereas 2000 is a leap year.

As 1700 is a centurial year which is not divisible by 400 whereas 2000 is a centurial year divisible by 400.

In this tutorial, you will learn how to write C program to check if the input year is leap year on not.

Approach of Program:

1) Take input year from the user

2) Use if-else statement to check the following conditions:

• Check if the year is divisible by 4 it is a leap year or else year is not leap year
• Check if the year is divisible by 100 it is not a leap year unless the year is also divisible by 400 then it’s a leap year
• Check if the year is divisible by 400 if yes the year is a leap year

3) Print the Output

## C Program to Check Leap Year

``````//Program to find the leap year

//Including the standered input output header library
#include <stdio.h>
//Main Function
void main(){
int x;
//Giving a hint to user what to enter
printf("Enter A Year : ");
// Take year input from user
scanf("%d",&x);

//Checking the entered number modulation is 0 or not
if(x % 4 == 0){
//If Yes
//Checking the entered Year modulation is 0 or not with 100
if( x % 100 == 0)
{
//If Yes
//Checking the entered Year modulation is 0 or not with 400
if ( x % 400 == 0)
{
//If Yes
printf("%d is a leap year.", x);
}
else
{
//If No
printf("%d is not a leap year.", x);
}
}
else
{
//If No
printf("%d is a leap year.", x );
}
}else{
//If No
printf("%d is not a leap year.", x);
}

}
``````

Output 1 (Leap Year)

``````Enter A Year: 2312
2312 is a leap year``````

Output 2 (Not A Leap Year)

``````Enter A Year: 2019
2312 is not a leap year``````