How to Check Leap Year in C?


Problem: Write a program in C to check whether the given year is leap year or not.


Input:  2020
Output: Leap Year

Input:  2021
Output: Not a Leap Year

A year is said to be a leap year if it is divisible by 4. It mostly occurs every 4 years but every 100 years we skip a leap year unless it is divisible by 400.

If one year is divisible by 4, it is not necessary that it is a leap year. The following condition must be satisfied to be called a leap year:

  • If a year is divisible by 4 then it should not be divisible by 100.
  • Otherwise, the year should be divisible by 400.

If neither of the condition gets satisfied then the year is not a leap year.

Here is the source code to check leap year in C:

#include <stdio.h>
int main()
    int year;
    printf("Enter the year \n");
    if(year%4==0 && year%100 !=0)
        printf("Leap Year");
    else if(year%400==0)
        printf("Leap year");
        printf("Not a Leap Year");
    return 0;

Output 1:

Enter the year
Leap Year

Output 2:

Enter the year
Not a Leap Year

In this tutorial we learned to check leap year in C. If you have any doubts or suggestions then please comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *