C++ program to find leap year using nested if

C++ program to find leap year using nested if. Check the year is leap or not program in C++. This program will check the year whether it is leap year or not. Here’s the easiest way to find the year is leap year or not in simple c++ program for beginners in c++ programming language.

#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

What is leap year and why it happens for every four years

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.

What is nested if else in c++ programming

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.