C++ Leap year program

Let’s see how to check leap year.

  • The year which is divisible by 400 is a leap year. For example, 1200, 1600, 2000, 2400 are leap years.
  • The year which is divisible by 4 is leap year but which is divisible by 100 is not leap year. That means century year is not leap year except which are divisible by 400. For example, 1300, 1500, 1900 are not leap year because they are divisible by 100. But 1992, 1996, 2004 etc are leap years as they are divisible by 4.

Program to check leap year in C++

In the bellow program we will check a year using the above condition to check it. Let’s see the program to check leap year.

// C++ program to check leap year

#include <iostream>
using namespace std;

int main(){
    int yr;

    cout <<"Enter the year you want to check : ";
    cin >>yr;

    if(yr%4 == 0){
    
        if(yr%100 == 0){
        
            if(yr%400 == 0){
                cout << "\nLeap year.\n";
                
            }else{
                cout << "\nNot leap year.\n";
            }
            
        }else{
            cout << "\nLeap year.\n";
        }
        
    }else{
        cout << "\nNot leap year.\n";
    }
    
    return 0;
}

Output of leap year program

leap-year-program-in-c-check-leap-year

You can also see the leap year program in C language.

Previous pageFind largest number

Next pageFind factors