C program to check given year is Leap year or Not | Leap year program in C

Spread the love

What is Leap Year :

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

Formula to Calculate Leap Year :

Generally we all know that, If a year is perfectly divisible by 4 then that year is called as Leap year. But is it correct ?? No. because the years which are divisible by 100 are not leap years , Except the years like 400,800,..( i.e years which are divisible by 400).

If your confused here is the small Algorithm to calculate Leap year .

Algorithm to Calculate 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 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
  • if a year is divisible by 100 and not divisible by 400 then it is not Leap year.  

Here is the one more algorithm :

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 the Leap year.
Now we will try to write a C program to that takes one year as Input and it will decides weather it is Leap year or not.

Program : C program to Check given year is Leap year or not :

  1. #include <stdio.h>
  2. int main()
  3. {
  4.   int year; 
  5.   printf(“Enter a year to check if it is a leap year : “);
  6.   scanf(“%d”, &year);
  7.  
  8.   if ( year%400 == 0)
  9.     printf(“%d is a leap year.n, year);
  10.  else if ( year%100 == 0)
  11.     printf(“%d is not a leap year.n, year);
  12.   else if ( year%4 == 0 )
  13.     printf(“%d is a leap year.n, year);
  14.   else
  15.     printf(“%d is not a leap year.n, year);  
  16.   return 0;
  17. }

Output :

Related Programs :

  1. Welcome note program to Sillycodes
  2. Calculating Student Grade
  3. C program to Convert Temperature.
  4. C program to understand type conversation.
  5. finding Largest of two numbers using conditional operator in C.
  6. C program to calculate the simple Interest,
  7. C program to understand Size of Operator 
  8. 100 + More C programs


Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

Leave a Reply