on Leave a Comment

C++ Program to Check Leap Year

This article contains C++ program to check whether a year is leap year or not.

Leap year is a year comes after every four year containing 366 days including 29 February as an intercalary day.

A year is a leap year if:

1. Year is divided by 4 but not by 100.
2. Century year (1600, 2000 etc) is divided by 400 and 100.

C++ Program to Check Whether a Year is Leap Year or Not

#include<iostream>
using namespace std;
int main()
{
    int y;
    cout<<"Enter year : ";
    cin>>y;
    if((y%4==0 && y%100!=0) || (y%400==0))
    {
        cout<<endl<<y<<" is a leap year";
    }
    else
        cout<<endl<<y<<" is not a leap year";
    return 0;
}

OUTPUT 1:

Enter year : 2018

2018 is not a leap year


OUTPUT 2:

Enter year : 2008

2008 is a leap year


0 comments:

Post a Comment