Leap Year Program in Cpp in 2022? is 2022 a leap year or not? - mymixindia.com

Leap Year Program in Cpp in 2022? is 2022 is a leap year or not?


Leap Year Program in Cpp in 2022? is 2022 is a leap year or not?

//......Mymixindia.com......
//......Leap Year Program in Cpp 2022.......
//........Is 2022 a leap year or not...........
#include<iostream>
using namespace std;

int main(){

 int year; //...year variable....

    cout << "Enter a year to check the given year is a leap year or not ? : ";
    cin >> year; //....user input - year...

    if (year % 4 == 0) { //....first check with divisible by 4......
        if (year % 100 == 0) { //....second check with divisible by 100......
            if (year % 400 == 0) //....last check with divisible by 400......
                cout <<"The given year " <<year << " is a leap year.";
            else
                cout <<"The given year " <<year << " is not a leap year.";
        }
        else
            cout <<"The given year " <<year << " is a leap year.";
    }
    else
        cout <<"The given year " <<year << " is not a leap year.";

    return 0;
}

The output of the leap year program

Enter a year to check the given year is a leap year or not ? : 2004
The given year 2004 is a leap year.

Enter a year to check the given year is a leap year or not ? : 2018
The given year 2018 is not a leap year.

Now, check whether the current year 2022 is a leap year or not?

Enter a year to check the given year is a leap year or not ? : 2022
The given year 2022 is not a leap year.

The current year is not a leap year.

 

Related Posts:

Pointer Program with Aaary and Function in Cpp 2022

Pointer Program in Cpp 2022

Program to Print Prime Number in CPP 2020

5 Namespace Program in C++ 2022

Constructors Program in Java

Java Data Type Program

HTML Tutorials 

CSS tutorials