In this tutorial you will learn about the C Program to Check Leap Year or Not and its application with practical example.
C Program to Check Leap Year or Not.
In this tutorial, we will learn to create a C program that will Check Leap Year or Not in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- String functions in c programming.
Check Leap Year or Not.
As we all know the c programming is a very powerful language. In the c programming language, we have many pre-defined functions for arithmetic operations. but today we will check whether the given number is a leap year or not with the help of the c programming language.
With the help of this program, we can Check Leap Year or Not.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declare the variables for the program. 2. Take the input number from the user. 3. Pass that number to a condition. 4. Calculate the leap year from the given number. 5. Print the output string after checking. 6. End the program. |
Program to Check Leap Year or Not:-
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 |
#include <stdio.h> int main() { //declaring the variable for the program int yr; //taking input year printf("Enter the year to check: "); scanf("%d", &yr); // leap year if perfectly divisible by 400 if (year % 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) { //printing output printf("%d is a leap year.", yr); } // all other years are not leap years else { //printing output 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 of number input.
Taking input number from the user.
Calculating and Printing output of the program.