C++ Program To Check Year Is Leap Year Or Not Using If/Else Statements

#include <iostream>
using namespace std;
int main() {
    int y;
    // y - denotes the year
    cout << "----Enter the year----\n";
    cin >> y;
    if (y % 400 == 0) {
        cout << "\n" << y << " is the leap year.\n";
    } else if (y % 100 == 0) {
        cout << "\n" << y << " is not the leap year.\n";
    } else if (y % 4 == 0) {
        cout << "\n" << y << " is the leap year.\n";
    } else {
        cout << "\n" << y << " is not the leap year.\n";
    }
    return 0;
}

OUTPUT:

----Enter the year----
1997
1997 is not the leap year.

Sharing Is Caring

Leave a Comment