Check Leap year program in C Language

check-leap-year-program-in-c-programming-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:

Output:

Example 2: Input:

Output:

What is Leap Year :

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

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:

  1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
  2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
  3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
  4. The year is a Leap year (it has 366 days).
  5. 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)
else
if (year is not divisible by 100) then (it is a leap year)
else
if (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:

Program Output:

check-leap-year-program-in-c

Related Programs :

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

3 Responses

  1. […] C Program to given year is Check Leap year or Not […]

  2. […] 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/ […]

  3. […] C Program to check given Year is Leap Year or Not […]

Leave a Reply