Is the year a leap year? - C++ Program

Q. Write a C++ program to check whether the input year is a leap year or not.

Answer:

Following program is checking whether the entered year is a leap year or not. If year is divisible by 400 then it is a leap year. For example, 1600, 2000 etc. are leap year but 1500, 1700 etc. are not leap year. If year is not divisible by 400 and 100 but divisible by 4 then the year is a leap year.

#include<iostream>
using namespace std;
int main()
{
        int year;

        cout<<"\n Enter Year : ";
        cin>>year;

        if((year%4==0) && (year%100!=0))
        {
                cout<<"\n This is a Leap Year";
        }
        else if(year%100==0)
        {
                cout<<"\n This is not a Leap Year";
        }
        else if(year%400==0)
        {
                cout<<"\n This is a Leap Year";
        }
        else
        {
                cout<<"\n This is not a Leap Year";
        }
        return 0;
}


Output:

leap year