Program to check Leap year or not in C++ || Conditional Statement || C++
In this we are going to see how to make a Program in C++ to check whether the Year is a Leap Year or not.

The code given below can be used for TURBO C++ Compiler:-

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
	int a;
	cout<<"enter year \n";
	cin>>a;
    //leap year is perfectly divisible by 400
	if(a%400 == 0)
	{
		cout<<"The entered year is a leap year \n";
	}
	//not a leap year if divisible by 100 but not 400
	else if( a%100 == 0)
	{
		cout<<"The entered year is not a leap year \n";

	}
	//leap year is perfectly divisible by 4
	else if(a%4==0)
	{
		cout<<"The entered year is a leap year \n";
	}
	else
		cout<<"The entered year is not a leap year"<<endl;
	getch();
}
    
    

The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int main()
{
	int a;
	cout<<"enter year \n";
	cin>>a;
    //leap year is perfectly divisible by 400
	if(a%400 == 0)
	{
		cout<<"The entered year is a leap year \n";
	}
	//not a leap year if divisible by 100 but not 400
	else if( a%100 == 0)
	{
		cout<<"The entered year is not a leap year \n";

	}
	//leap year is perfectly divisible by 4
	else if(a%4==0)
	{
		cout<<"The entered year is a leap year \n";
	}
	else
		cout<<"The entered year is not a leap year"<<endl;

	return 0;
}
    
    

#ENJOY CODING
 

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post