Check Leap Year Program Example using CPP

  1. Home
  2. Tutorials
  3. CPP
  4. CPP Programs
  5. If Else Statement
  6. Program

Source Code

#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    
    // Variable Declaration for input
    int y;

   // Taking Yesr input in Variable y
    cout<<"Enter Number: ";
    cin>>y;

   // Checking Leap year using if else statement

    if ( y % 4 == 0 )
        cout<<"Leap Year \n";
    else
        cout<<"Not a Leap Year \n";
    
    return 0;
}

Output

check whether a given year is leap or not using if else statemenet in c++Working

This program declare one variable of int type to store year input. This variable is named as y. After this input statement having cin is used to get input from user. A year is called leap year if it is divisible by 4. Mean if we take remainder of year by 4 and it gives 0, then it will called leap year. For this purpose we use if else statement in source code.

Example of Leap Years:

Some examples of leap years are as below as these are completely divisible by 4.

2000, 2004, 2008, 2016, 2020............

 

Comments
Login to TRACK of Comments.