Program to check leap year

0 Suresh Chand March 28, 2021

In this example, We will check whether the year given by the user is a leap year or not. To understand this example, You must knowledge in following topics of the C++ programming language.

All the years which are perfectly divisible by the 4 are leap years. But the years ends with 00 (Century Years) are leap year only when they are perfectly divisible by 400.

For example: 2004, 2012, 2400 are leap years.

In this program we will check whether year is leap year or not. Let’s look an example.

#include <iostream>
using namespace std;

int main() {
    int year;

    cout << "Enter a year: ";
    cin >> year;

    if (year % 4 == 0) {
        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.";
    }
    else
        cout << year << " is not a leap year.";

    return 0;
}

The output of above program is

Enter a year: 2014
2014 is not a leap year.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

!

Ads

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System