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: 

  1. The primary condition for leap year is that it is divisible by 4.
  2. 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:

  1. Program to find sum of first ‘n’ natural numbers.
  2. Program to Reverse a Number.
  3. Program to swap two Numbers.
  4. Program to print Fibonacci Series up to Nth Term.
  5. Program to find and print nth Fibonacci number.
  6. Program to find Power of the Number.
  7. Program to find Quotient and Remainder.
  8. Program to find largest amongst three numbers.
  9. Program to find factorial of a number.
  10. Program to find GCD of two numbers.
  11. Program to find LCM of two numbers.
  12. Program to check whether entered number is odd or even.
  13. Program to check whether entered number is prime number or not.
  14. Program to check whether entered number is palindrome or not.
  15. Program to check whether entered number is Armstrong Number or Not.
  16. Program to convert binary number to octal number.
  17. Program to convert binary number to decimal number.
  18. Program to convert binary number to hexadecimal number.
  19. Program to convert octal number to binary number.
  20. Program to convert octal number to decimal number.

You may also like...