C Program to check whether a year is a leap year

In this example, we will take year as input and check entered year is leap year or not.

C Program to Find Year is Leap Year or Not

A leap year is a year that has 29 days in the month of February. This is done to keep the calendar year the same as the astronomical year because astronomical years have a quarter of a day more than the calendar year. This is why a leap year occurs once every 4 years.

To determine whether a year is a leap year, follow these steps:

  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).

Example :

	
#include <stdio.h>
int main() {
    int year;
    printf("Enter year: ");
    scanf("%d", &year);

    if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
        printf("%d is a leap year", year);
    else
        printf("%d is not a leap year", year);

    return 0;
}
	

Output :

	
//Output :- 1
Enter year: 2020
2020 is a leap year
//Output :- 2
Enter year: 2021
2021 is not a leap year
	

Share your thoughts

Ask anything about this examples