Leap Year Program in C

In this article, we will study the leap year program in C. Let’s first define a leap year before we go into the C program to check if the user-entered year is a leap year or not.

What is a Leap Year?

Every four years, there is a year known as a leap year. According to the Gregorian calendar, a year should have 365.25 days in it. However, because we count a year as having 365 days, the extra 0.25 days are added to the next year’s calendar, bringing the total to 1 day in the fourth year. Consequently, a leap year has 366 days instead of 365. The extra day is added, making February 29.

How to Find a Leap Year?

You only need to enter a few mathematical conditions with the aid of the If statement in the program code to determine if a year is a leap year or not. The following criteria must be met to determine whether a particular year is a leap year or not:

  • The entering year must divide evenly by four but not by 100.
  • The year entered must divide evenly by 400.

To differentiate between leap years and century years, utilize the second condition. The years ending in ’00 are known as century years, examples are 1300, 1500, 1400, and so on. Only when a century year is equally divisible by 400 is it recognized as a leap year. For instance, since 1200, 1600, and 2000 all precisely divide by 400, they are all century leap years.

How to Implement Leap Year Program in C?

#include <stdio.h>
int main()
   int y;
   printf("Enter the year to check: ");
   if (((y % 4 == 0) && (y % 100!= 0)) || (y%400 == 0))
      printf("It is a leap year");
      printf("It is not a leap year");
   return 0;

C Program to Find Leap Years Within a Given Range

In the last example, we asked the user to enter a year and determined whether or not it was a leap year. But in this case, we’ll create a leap year C program that will prompt the user for a range and print out all the leap years that fall within that range.

#include <stdio.h>
int main()
    int start_Year, end_Year, i;
    printf("Enter the starting year of the range: ");
    printf("Enter the last year of the range: ");
    //the given range
    printf("Leap Years between %d and %d are: \n", start_Year, end_Year);
    for (i= start_Year; i<= end_Year; i++)
        if (((i % 4 == 0) && (i % 100!= 0)) || (i % 400 == 0))
            printf("%d \n", i);
    return 0;

A similar idea may be used to determine various time periods. Sometimes the if-else statements in C are introduced using the C program for the leap year. Join our platform to learn more about C’s foundational concepts, such as pointers and loops. The site offers a huge selection of free online courses that may assist you in learning the fundamentals of several programming languages, including C.

Other C Programs

C Program for Binary Search
C Program to Add Two Numbers
C Program to Calculate Percentage of 5 Subjects
C Program to Convert Binary Number to Decimal Number
C Program to Convert Celsius to Fahrenheit
C Program to Convert Infix to Postfix
C Program to Find Area of Circle
C Program to Find Roots of Quadratic Equation
C program to Reverse a Linked List
C program to reverse a number
Ascending Order Program in C
Menu Driven Program For All Operations On Doubly Linked List in C
C Program for Armstrong Number
C Program For Merge Sort For Linked Lists
C program for performing Bubble sort on Linked List
Hello World Program in C
Perfect Number Program in C
Odd Even Program in C
Selection Sort Program in C

Leave a Reply

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