Leap Year Program in C++ Using If Else

C++ Program to check leap year. Here’s the easiest way to find the year is leap year or not in simple c++ program for beginners.

#include <iostream>
using namespace std;
int main() 
{
int year;
cout << "Enter the number";
cin >> year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is leap year";
else
cout << year << " is not leap year";
}
else
cout << year << " is leap year";
}
else
cout << year << " is not leap year";
return 0;
}

 

Output:

Enter the number 2020

2020 is leap year

Leap Year and Why it is Happen

The Earth’s orbit around the Sun takes around 365.25 days – a solar year. The days of a calendar year are generally rounded to 365. 

Every four years, we add one day to our calendar to compensate for the lost partial day. 

There are 366 days in a year, thus there are 366 days in a year. This is referred to as a leap year.

“And because February was the final day of the year, an extra date was added in February to ensure that the first day of spring always coincided with the correct time.” 

A leap year occurs every four years on average, but there are outliers. If a year is equally divisible by four, it is a leap year.

Nested If Else in C++

An if-else statement containing another if statement as the if body or the else body is known as a nested if statement. 

Here’s an illustration:  

Evaluate the outer if condition if the outer if condition evaluates to true. Run the if body if it evaluates to true.