C++ Program to Check Leap Year

Here is a C++ program to check whether a year is leap year or not. A leap year is a year containing one additional day in order to keep the calendar year in sync with the astronomical year. Each leap year lasts 366 days instead of the usual 365, by extending February to 29 days rather than the common 28 days.
Example of leap years: 1980, 1984, 1988, 1992 ...

A year which is multiple of 4 is a leap year except for century years(years multiple of 100 like 1800, 1900 etc) which is leap year only it is perfectly divisible by 400.

C++ Program to check a year is leap year or not

#include <iostream>

using namespace std;
 
int main(){
    int year;
    cout << "Enter a year for leap year check\n";
    cin >> year;
     
    if(year%4 != 0){
        cout << year << " is not a leap year";
    } else {   
        if(year%100 == 0){
            if ( year%400 == 0){
                cout << year << " is a leap year";
            } else {
                cout << year << " is not a leap year";
            }
        } else {
            cout << year << " is a leap year";
        }
    }
    return 0;
}
Output
Enter a year for leap year check
2015
2015 is not a leap year
Enter a year for leap year check
2016
2016 is a leap year

Recommended Posts
C++ Program to Check Prime Number
C++ Program to Check for Armstrong Number
C++ Program to Find Transpose of a Matrix
C++ Program to find length of string
C++ Program to Check Whether Number is Even or Odd
C++ Program to Check Strings are Anagram or Not
C++ Program to check Whether a Number is Palindrome or Not
C++ program to Check Whether a Number can be Split into Sum of Two Prime Numbers
C++ Program to Copy String Without Using strcpy
C++ Program to Count Words in Sentence
C++ Program to Check Prime Number Using Function
All C++ Programs