C Program To Check Leap Year | LearntHub

Hello friends, in this post today, we will learn to check whether the year entered by user is leap year or not a leap year. 
Before starting the program, we need to know about that what is leap year.

Leap Year:-

The leap year is 366 days, While there are 365 days in every year, every fourth year is a year. The year in which a day is increased is called a leap year.
Leap Year

In the leap year, February is mainly 29 days, while in other years, February is only 28 days.

Formula:-


If a year is divided by 100, it is not a leap year, but if the same year is completely divided by 400, then it is a leap year Or the year can be divided by four, like the year 2008 can be divided by 4, 100 and 400 so it is leap year, if we take year 2007, it can be devided by 100 but can't devided by 4 and 100, so it is not a leap year.
Read Also:
  1. Operators
  2. Conditions Statements
  3. Loops

Program 1:-


Output:

Enter Year: 2008
2008 is a leap year.

Program 2:-


Output:

Enter Year: 2017
2017 is not a leap year.

Explanation of above program:-

In the above program, you have to put a condition that whether Y%400==0; if yes, prints that the given Y is a leap year. Using else if, another condition is checked whether Y%100==0; prints, the year is not a leap year.
Again using else if another condition is checked whether Y%4==0; if the condition is true, prints the message, Y is a leap year Or else prints, Y is not a leap year. Where Y is year like 2001, 2002.....2nnn.

Post a comment

3 Comments