C++ Program to check a Leap Year or not
In this example program, you will learn about how to check if a given year is a leap year or not in C++.
#include<iostream>
using namespace std;
int main() {
int year;
cout << "Enter a year in (yyyy) format: ";
cin >> year;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
cout<<year<<" is a leap year";
else
cout<<year<<" is not a leap year";
return 0;
}
Output:
Enter a year in (yyyy) format: 2020
2020 is a leap year
The logic in the above program is if a given year is divisible by 4 and 100 but not divisible by 400 it is a common year else the given year is a leap year.