Check Leap Year
“Check Leap Year” is a basic programming exercise problem. Here, we are given a year, entered by user and our task is to check whether an entered year is a leap year or not.
Condition to Check leap year:
- The primary condition for leap year is that it is divisible by 4.
- If the entered year is century year (i.e., 100,200,300 etc.), then it must be divisible by 400. Else, it will not be a leap year.
Example (Check Leap Year):
INPUT: Year = 2000 OUTPUT: Leap Year INPUT: Year = 2019 OUTPUT: Not Leap Year
C++ Program to check whether a year is leap year or not is as follows:
/* C++ Program to check leap year */
#include<bits/stdc++.h>
using namespace std;
int main()
{
int year;
//Scan the year
cout<<"Enter the year:";
cin>>year;
// Primary condition : Year must be divisible by 4
if(year % 4 == 0)
{
// Condition for century Year
if(year %100 == 0)
{
// Century Year must be divisible by 400
if(year % 400 == 0)
{
cout<<"Leap Year";
}
else
{
cout<<"Not Leap Year";
}
}
else
{
cout<<"Leap Year";
}
}
else
{
cout<<"Not Leap Year";
}
}
OUTPUT: Enter the year: 2000 Leap Year
Related Posts:
- Program to find sum of first ‘n’ natural numbers.
- Program to Reverse a Number.
- Program to swap two Numbers.
- Program to print Fibonacci Series up to Nth Term.
- Program to find and print nth Fibonacci number.
- Program to find Power of the Number.
- Program to find Quotient and Remainder.
- Program to find largest amongst three numbers.
- Program to find factorial of a number.
- Program to find GCD of two numbers.
- Program to find LCM of two numbers.
- Program to check whether entered number is odd or even.
- Program to check whether entered number is prime number or not.
- Program to check whether entered number is palindrome or not.
- Program to check whether entered number is Armstrong Number or Not.
- Program to convert binary number to octal number.
- Program to convert binary number to decimal number.
- Program to convert binary number to hexadecimal number.
- Program to convert octal number to binary number.
- Program to convert octal number to decimal number.