C Program to Check Leap Year

In the world of computer science, the concept of leap year plays a crucial role in various applications, especially when we are dealing with date and time calculation. A leap year occurs every four years to compensate for the fact that the Earth’s orbit around the sun takes approximately 365.25 days. In this article, we will write a C program that checks whether a given year is a leap year or not.

The rule for Leap Year

The rule for identifying a leap year is relatively simple and straightforward. A year is considered a leap year, if it is divisible by 4. However, to avoid excessive leap years, years divisible by 100 are not a leap year unless they are also divisible by 400. This rule ensures that years like 1700, and 1800 are not considered leap years while the years 2000, and 2400 are considered leap years because they are divisible by both 100 and 400.

Leap Year Flow Chart

leap year flowchart

C Program to Check Leap Year

Output

C Program to Check Leap Year

How the Above C Program Works?

  • The program asks the user to enter a year to check whether a given year is a leap year or not.
  • With the help of the if statement and leap year condition ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) program checks and prints whether the year entered by the user is a leap year or not.

C Program to Check Leap Year Using Ternary Operator

Output

C Program to Check Leap Year Using Ternary Operator

In the above C Program the ternary operator (? :) is used to check whether the entered year is a leap year or not.

Happy Coding!!

See Also

2 thoughts on “C Program to Check Leap Year”

Leave a Comment