# Leap Year Checking In C.

To check a year leap year or not you have to check a few matters. First of all, we will learn about what is a leap year? Then we will try to create some conditions to check a year leap year or not. Then I will try to show you the code in c with else if ladder conditional statements.

### What Is A Leap Year:

Leap year means a year that contains 366 days instead of 365 days. We know after every 4 years a year become 366 days. In that year February month contains 29 days instead of 28 days. This kind of year is called a leap year. Leap year is also called intercalary year and the 29th of February is called intercalary day. Actually, we know a year is counted as how much time the earth takes to complete a full cycle around the sun. And that is exactly 365.2421891 days. As the fraction is lower that’s why normally years are counted in 365 days. But for the fraction after every 4 years, a year is counted by 366 days. But the fraction is not accurately 0.25 it is less than that. So, every 3 consecutive centuries is not considered a leap year. But every 4th century was considered a leap year. That is because you can see in every 100 years total contains 36524.21891 days. Which is less than 1 day considering the leap year after every 4 years. That so why consecutively 3 century is not considered a leap year. But after every 400 years, there is also an increase in almost 1 day for the fraction. That’s so why Every 4th century is considered a leap year but the next 3 century is not considered a leap year.

#### Conditions:

From the above discussion, we have learned that every 4th century becomes a leap year. For example, 1600 is a leap year as it is a 4th-century. But without the 4th-century other centuries is not a leap year. Like 1700, 1800, and 1900 are not leap years but 2000 is a leap year. Without them, every 4th year is a leap year. So, we have to check 3 conditions for that:

1. Is the year divisible by 400? If yes. Then the year is a leap year.
2. If no. Then we have to check if the year is divisible by 100? If yes. Then this year is not a leap year.
3. If no. Then we have to check if the year is divisible by 4? If yes. Then it is a leap year otherwise it is not a leap year.

Code:

#include<stdio.h>
#define leap printf(“This is a leap yearn”)
#define not_leap printf(“This is not a leap yearn”)
int main()
{
int y;
scanf(“%d”,&y);
if(y%400==0)
{
leap;
}
else if(y%100==0)
{
not_leap;
}
else if(y%4==0)
{
leap;
}
else
{
not_leap;
}

return 0;
}

Input: 1778

Output: This is not a leap year

Input: 1500

Output: This is not a leap year

Input: 2000

Output: This is a leap year

Input: 2013

Output: This is not a leap year

Input: 1604

Output: This is a leap year

Here, to make the code easier I have used the #define function. As there needs to be print the same thing more than once. So, I define it before the main function so I used the constant name instead of the printf function whenever I needed it. You can also use the #define function to reduce your code size and also for saving your time. This will be good practice for you by using the #define function in your code. If you even don’t know about the #define function and how to use this in your code then you can read this.

If you still have any problems understanding this problem then comment below I will try to help you. And if you need any other problem solution then comment about the problem I will try to help you. Thank you.

Stay well. Stay home. Wash hands when coming from outside and wear a mask before going outside. Stay safe. Happy coding.