Do you want to write a c program to check the leap year? Well, there is more than one way to do so. Leap year is a special occasion that occurs every fourth consecutive year.
A leap year is followed by one extra day as compared to the normal days in a year, i,e 366 days in a leap year. In this article, let us write a c program to check leap year.
What makes up a Leap Year?
A normal calendar year has only 365 days while it takes approximately 365.25 days for Earth to orbit around the sun i,e a solar year. We round off the days to 365 days and adjust one day to our calendar every four years. That makes a Leap Year.
A leap year contains one additional day in February month i,e. February 29. Our problem statement is to write a leap year program in C.
How to Develop a Logic to Find a Leap Year?
The first step in writing a program is to develop the logic behind it. In this problem statement, we have to develop a program to find whether a given year is a leap year or not. A given year can only be a leap year when
- If a given year is a multiple of 4 but not 100
- If a given year is a multiple of 400
For example, 2020 is a leap year while 2019 is not a leap year.
Also, Check some Basics C Programs for Beginners
C Program to Check Leap Year using If Statement
Let us write a C program to check leap year using the if statement. You can enter any value (year) of your choice and will get whether the given year is a leap year or not.
| #include <stdio.h>
int main ()
{
int year;
printf("\n Please enter a year of your choice \n");
scanf( "%d", &year);
if ((year%400 ==0)||(year%4==0)&&(year%100!=0))
{
printf ("%d is a leap year.\n", year);
}
else
printf ("%d is not a leap year.\n", year);
return 0;
} |
Output
Explanation
With this C program, you can check whether a given year is a leap year or not. We are using a logical OR (||) and logical And (&&) expression to check for leap year. These logical OR and And operators help us check for multiple conditions within one if statement.
The first condition checks (year%4==0) whether the remainder of this expression is 0 or not. If the condition comes false then it will exit the condition and give output as “Not a leap year." If the given year is a multiple of 100, then it is not a leap year.
Both the conditions, are i,e (year%4 ==0) )and (year%100! ==0), must hold to be a leap year. If the (year%400 == 0) this statement evaluates to 1, then the year is a leap year.
C Program to check Leap Year using Else if Statement
This program allows users to check for a leap year using the else if statement. You can use multiple else if and else statements to find leap years. Check whether the year you use is a leap year or not.
| #include <stdio.h>
int main ()
{
int year;
printf(" Please enter a year of your choice \n");
scanf( "%d", &year);
if (year%400==0)
printf ("%d is a Leap Year. \n", year);
else if (year%100 ==0)
printf (" %d is not a leap year. \n", year);
else if (year%4 == 0)
printf ("%d is a leap year. \n", year);
else
printf ("%d is not a leap year. \n", year);
return 0;
} |
Output
Explanation
In this method, we will first check whether (year%400 == 0) is true. If it is true then the given year is a leap year. Otherwise, we will check whether (year%100==0), if it is true then the given year is not a leap year. At last, we check whether (year%4 == 0); if this is true then the given year is a leap year. And if no condition is satisfied, then the given year is not a leap year.
C Program to check Leap Year using Nested If Statement
You can also find whether a given year is a leap year or not using the nested If statement. We will use nested if to verify our logic and then produce the output.
| #include <stdio.h>
int main ()
{
int year;
printf( "Please enter a year of your choice \n");
scanf( "%d", &year);
if (year%4 == 0)
{
if (year%100 ==0)
{
if (year%400 == 0)
printf ("%d is a leap year.", year);
else
printf ("%d is not a leap year.", year);
}
else
printf ("%d is a leap year.", year);
}
else
printf ("%d is not a leap year.", year);
return 0;
} |
Output

Explanation
In this method, we use nested if statements to find whether a given year is a leap year or not. In the first statement, we check whether the given (year%4==0) is true or not. If the expression is true, then we will move to the next condition, however, if it is false, then the year is not a leap year.
In the second statement, we check whether (year%100) is false. If it is false, then the given year is a leap year, and if it is true, then we have to check whether the given year is divisible by 400 or not.
In the third statement, we check whether the given number is divisible by 400 or not. If the remainder of (year%400 == 0) is false, then the given number is definitely not a leap year.
Learn DSA with C++ with PW Skills
Are you looking for a career in software development, web development, or a similar profile? If you are choosing C++ language then PW Skills is here to help you master Data Structures with C++ programming. You will learn the basics and fundamentals of C++ programming and develop your skills.
You will be able to solve competitive programming and work on real-time projects. This is a self paced course covered by expert mentors. Hurry! Start your career with PW Skills.
Enroll in our Decode DSA with C++ and master competitive programming and Data Structure.