C++ Program to Find Year is leap Year

Write a C++ Program to Find Year is leap Year with an example. In this leap year example, we used the If statement to check whether 

  • year % 400 equals 0 – Year divisible by 400 is a leap.
  • ( year % 4 == 0 ) && ( year % 100 != 0)) – Any year divisible by 4 and that is a century year, then it is a leap.
#include<iostream>
using namespace std;

int main()
{
	int year;
	
	cout << "\nPlease Enter the Year to Check the Leap Year =  ";
	cin >> year;
	
	if (( year % 400 == 0) || (( year % 4 == 0 ) && ( year % 100 != 0)))
	{
		cout << "\n" << year << " is a Leap Year";
	}
	else
	{
		cout << "\n" << year << " is Not a Leap Year";
	}

 	return 0;
}
C++ Program to Find Year is leap Year 1

Let me check with another.

Please Enter the Year to Check the Leap Year =  2020

2020 is a Leap Year

C++ Program to Find Year is leap Year using Else If statement

#include<iostream>
using namespace std;

int main()
{
	int year;
	
	cout << "\nPlease Enter the Year to Check =  ";
	cin >> year;
	
	if (year % 400 == 0)
	{
		cout << "\n" << year << " is a Leap Year";
	}
	else if ( year%100 == 0)
	{
		cout << "\n" << year << " is Not a Leap Year";
	}
	else if ( year % 4 == 0 )
	{
		cout << "\n" << year << " is a Leap Year";
	}
	else
	{
		cout << "\n" << year << " is Not a Leap Year";
	}

 	return 0;
}
Please Enter the Year to Check =  2024

2024 is a Leap Year

This Program helps to check Year is a leap Year using the Nested If statement.

#include<iostream>
using namespace std;

int main()
{
	int year;
	
	cout << "\nPlease Enter the Year to Check =  ";
	cin >> year;
	
	if(year % 4 == 0)
	{
		if( year % 100 == 0) 
		{
			if ( year % 400 == 0)
			{
				cout << "\n" << year << " is a Leap Year";
			}
			else
			{
				cout << "\n" << year << " is Not a Leap Year";
			}
		}
		else
		{
			cout << "\n" << year << " is a Leap Year";
		}
	}
	else
	{
		cout << "\n" << year << " is Not a Leap Year";
	}

 	return 0;
}
Please Enter the Year to Check =  2016

2016 is a Leap Year

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.