Leap year program in C: To check whether the given year is a leap year or not.

What is a leap year?
Leap year is calendar year having one extra day which is to make a synchronized and seasonal year. Leap year contains 366 days while one ordinary year has 365 days.

Rules for leap year:
The year is leap year which is perfectly divided by 4 – excepts for year divisible by 100 and not by 400.
The century years are leap years such as 1600, 2000 and century years 1700, 1800,1900 are not leap year.

How we find leap year:
The number (year) perfectly divisible by 400 and 4 is a leap year.
And number perfectly divided by 100 and other year is not leap year.
Now, we know how to find the year is a leap year or not, so let’s see the leap year program in c.

Algorithm to check leap year

  1. Take the input year. year
  2. If year % 400 == 0 or year%4==0)
    print year leap year
    else If year % 100 == 0
    print year is not leap year
    else
    print year is not leap year

Leap year program in C

#include<stdio.h>
int main()
{
int year;
printf("Enter the year you want to check\n");
//take a user input
scanf("%d",&year);
//check leap year.
if(year%400==0)
{
printf("%d is leap year\n",year);
}
else if(year%100==0)
{
printf("%d is not a leap year\n",year);
}
else if(year%4==0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d is not a leap year\n",year);
}
}

 

Output:

Leap year program in C

Write A Comment