# Check Leap year program in C Language

**Introduction:**

In this article, We will look at the** Leap year program in C Language**. We also look at the algorithm for the Leap Year.

**Expected Output:**

**Example 1 : Input:**

1 |
Enter a year to check if it is a leap year : 2010 |

**Output:**

1 |
2010 is not a Leap year. |

**Example 2: Input:**

1 |
Enter a year to check if it is a leap year : 2020 |

**Output:**

1 |
2020 is a Leap year. |

**What is Leap Year :**

- A
**leap year**is a(a Leap year has 366 days and February month consists of 29 days instead of 28).__year containing one additional day in the month of February__

**Formula to check Leap Year :**

Generally, we all know that, *If a year is perfectly divisible by 4 then that year is called a Leap year.*

But is it correct? â€“ **No**.

Because the years are divisible by 100 do not leap years, Except the years like 400, 800,..( i.e years which are divisible by 400 are leap years).

If you are confused here is the Algorithm to calculate Leap year.

**Algorithm to Check Leap Year:**

- If the year is evenly
**divisible by 4**, go to**step 2**. Otherwise, go to**step 5**. - If the year is evenly
**divisible by 100**, go to**step 3.**Otherwise, go to**step 4**. - If the year is evenly
**divisible by 400**, go to**step 4**. Otherwise, go to**step 5**. - The
**year is a Leap year**(it has 366 days). - The
**year is not a Leap year**(it has 365 days).

**This algorithm is saying if a year is divisible by 4 it is Leap year **

**but we have a few conditions those are (Â Note : Below two conditions apply only for years like 100,200,300,400,500,â€¦etc)**

**if a year is divisible by 100 and 400 then it is Leap Year. ex: 400,800, etc****if a year is divisible by 100 and not divisible by 400 then it is not a Leap year.Â**

**Check Leap Year Program Psuedo Code:**

**if (year is not divisible by 4) then (it is a common year)elseif (year is not divisible by 100) then (it is a leap year)elseif (year is not divisible by 400) then (it is a common year)else (it is a leap year)**

Hope Now you know what is Leap year and How to calculate a Leap year.

Now we will try to write a C program that takes one year as Input and it will check whether it is a Leap year or not.

**Leap year program in c:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* Â Â Â Â Program: Check Leap Year Program Â Â Â Â Author: Sillycodes.com */ Â #include <stdio.h> int main() { Â Â Â Â int year; Â Â Â Â // Take the Input from the user, Store it in 'year' variable Â Â Â Â printf("Enter a year to check if it is a leap year : "); Â Â Â Â scanf("%d", &year); Â Â Â Â Â // Check if the year is divisable by '400', Â Â Â Â // If it is perfactly divisable by '400', Then it is a Leap Year Â Â Â Â if ( year%400 == 0) Â Â Â Â { Â Â Â Â Â Â Â Â printf("%d is a Leap year.\n", year); Â Â Â Â } Â Â Â Â else if ( year%100 == 0) Â Â Â Â { Â Â Â Â Â Â Â Â // If 'year' is not divisable by 400, but divisable by 100 Â Â Â Â Â Â Â Â // Then it is not a Leap Year Â Â Â Â Â Â Â Â printf("%d is not a Leap year.\n", year); Â Â Â Â Â Â Â Â Â Â Â Â } Â Â Â Â else if ( year%4 == 0 ) Â Â Â Â { Â Â Â Â Â Â Â Â // If 'year' is perfactly divisable by '4', Â Â Â Â Â Â Â Â // And not a Century year, Then it is a Leap Year Â Â Â Â Â Â Â Â printf("%d is a Leap year.\n", year); Â Â Â Â } Â Â Â Â else { Â Â Â Â Â Â Â Â // If any of the above Conditions are not True Â Â Â Â Â Â Â Â // Then given Year is 'Not a Leap' Year Â Â Â Â Â Â Â Â printf("%d is not a Leap year.\n", year); Â Â Â Â } Â Â Â Â return 0; } |

**Program Output:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ gcc leap-year-program.c $ ./a.out Enter a year to check if it is a leap year : 2000 2000 is a Leap year. $ ./a.out Enter a year to check if it is a leap year : 2020 2020 is a Leap year. $ ./a.out Enter a year to check if it is a leap year : 1900 1900 is not a Leap year. $ ./a.out Enter a year to check if it is a leap year : 2022 2022 is not a Leap year. $ ./a.out Enter a year to check if it is a leap year : 2010 2010 is not a Leap year. $ ./a.out Enter a year to check if it is a leap year : 100 100 is not a Leap year. $ |

## 3 Responses

[â€¦] C Program to given year is Check Leap year or Not [â€¦]

[â€¦] we have already covered the Leap year program in the following article â€“ Please look at it for more details about the Leap year formula â€“ https://sillycodes.com/c-program-to-check-given-year-is-leap/ [â€¦]

[â€¦] C Program to check given Year is Leap Year or Not [â€¦]