In this tutorial you will learn about the C Program to find the Leap Year and its application with practical example.
C Program to find the Leap Year
In this tutorial, we will learn to create a C program that will find the Leap Year in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in C Programming.
What is a Leap year?
A leap year contains 366 days. Leap year occurs every fourth year and has one extra day that day is adjusted in February month. The leap year means a year that must be divisible by four rather than the end-of-century years, which must be divisible by 400. This means that the year 2000 was a leap year, but 1900 was not.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input year from the user. 3. Finding that year is a leap year or not. 4. Printing the result. 5. End the program. |
Program to find the Leap Year
In this program today, we will take the integer input from the user as a year and store it in a variable. Then we will pass that variable to a conditional statement to check whether it’s a leap year or not. After that, we will print the output to the console.
With the help of this program, we can find the Leap Year.
Program code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* C program to <strong>find the Leap Year</strong> */ #include <stdio.h> int main() { //Declaring the variable required for the program. int yr; //taking the input from the user for the program. printf("Enter a year: "); scanf("%d", &yr); // leap year if perfectly divisible by 400. if (yr % 400 == 0) { printf("%d is a leap year.", yr); } // not a leap year if divisible by 100. // but not divisible by 400. else if (yr % 100 == 0) { printf("%d is not a leap year.", yr); } // leap year if not divisible by 100. // but divisible by 4. else if (yr % 4 == 0) { printf("%d is a leap year.", yr); } // all other years are not leap years. else { printf("%d is not a leap year.", yr); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- yr = it will hold the integer value.
Taking input year from the user.
Calculating the leap year using the program.
Printing Output year.