C++ Program to Check Leap Year

  • Write 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