C++ Program to Check if the Year is a Leap Year or Not

Check if a Year is a Leap Year or Not in C++

Given an integer input for a year, the objective is to check whether the given integer input represents a Leap year or not. In order to do so, we’ll check for two conditions, any year to be a leap year must satisfy either of them.

Example

Input: 2020

Output: It's a Leap Year

Flow Diagram:-

Leap year or not.png

Code:-

  • step 1: Start

  • step 2: Read year

  • step 3: if year%4=0 and year%100!=0 or if year%4=0 and year%400=0 then go to step 4
    else go to step5

  • step 4: print a leap year

  • step 5: print not a leap year

  • step 6: Stop

Algorithm:-

Code:-

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int year;

    cout << "Enter Year:" << endl; 
    cin >> year;

    if(year % 400 == 0)
        cout << year << " is a Leap Year";
        
    else if(year % 4 == 0  && year % 100 != 0)
        cout << year << " is a Leap Year";
        
    else
        cout << year << " is not a Leap Year";
    
    return 0;
}

Output:-

2100

2100 is not a Leap Year