Check Leap Year C Program

By | September 18, 2015

C Program To Check Leap Year

Learn How To Check Leap Year in C Programming Language. We have listed a well-researched Algorithm and Logic below for this program. To understand this program code efficiently, you must know How A Modulus Operator Works in C Programming Language. This code finds if a year entered by the User is a Leap Year or not using If Else Block Structure.

What is a Leap Year?

A Regular Year consists of 365 days. However, a Leap one consists of 366 days. It occurs after every three years and every fourth consecutive year is Leap. It consists of 52.2857 Weeks. This Leap Year C Program is based on the Gregorian Calendar.

Example

2004, 2008, 2012, 2016

Also Read: C Program To Delete Vowels From A String

C Program To Check Leap Year using If Else

#include<stdio.h>

int main()
{
      int l_year;
      printf("\nEnter a Year:\t");
      scanf("%d", &l_year);
      if(l_year%400 == 0)
      {
            printf("\n%d is a Leap-Year\n", l_year);
      }
      else if(l_year%4 == 0)
      {
            if(l_year%100 == 0)
            {
                  printf("\n%d is not Leap\n", l_year);
            }
            else
            {
                  printf("\n%d is a Leap-Year\n", l_year);
            }
      }
      else
      {
            printf("\n%d is not Leap\n", l_year);
      }
      return 0;
}

C Program To Find Leap Years from 1 To N

#include<stdio.h>

int main()
{
      int year, limit, count;
      printf("Enter The Starting Year:\t");
      scanf("%d", &year);
      printf("Enter The Ending Year:\t");
      scanf("%d", &limit);
      do
      {
            if(year % 400 == 0)
            {
                  printf("\n%d is a Leap Year\n", year);
                  year++;
            }
            else if(year%4 == 0)
            {
                  if(year%100 == 0)
                  {
                        printf("\n%d is not Leap\n", year);
                        year++;
                  }
                  else
                  {
                        printf("\n%d is a Leap-Year\n", year);
                        year++;
                  }
            }
            else
            {
                  printf("\n%d is not a Leap Year\n", year);
                  year++;
            }
      }while(year <= limit);
      return 0;
}

Output

Code To Check Leap Year in C Programming Language

Also Read: C Program To Print Map of India

 

In case you get any Compilation Errors with this Code To Check Leap Year in C Programming Language or you have any doubt about it, let us know about it in the Comment Section below.

6 thoughts on “Check Leap Year C Program

  1. David Augusta

    Finally I got this code! This is just so easy to understand with all the conditions in different If Else blocks. Thank you so much!

    Reply
  2. Mahesh Kartik

    I was wondering if it is possible to find the date of the leap year in this C Program?

    Reply
    1. Tushar Soni Post author

      Yes. You can definitely find the leap year date in this C Code. However, that might make the code more complex, but its not that difficult. You need to find in a Library function that checks the date. There are some library functions available under the header .

      Reply
  3. Vijay Lumar

    This the most self explanatory code for leap year in C programming. I find it really easy to understand. Thanka for clearing my concepts about leap year.

    Reply
  4. Rajesh Srivastav

    The If-Else structure has helped a lot to understand the logic behind a C program to find if the year is a leap year or not. Thanks.

    Reply

Let's Discuss