Write a C++ program that will check whether a year is leap year or not by taking user input

A year that has 366 days is called a leap year.
A year can be checked whether a year is leap year or not by dividing the year by 4, 100 and 400. If a number is divisible by 4 but not by 100 then, it is a leap year. Also, if a number is divisible by 4, 100 and 400 then it is a leap year. Otherwise the year is not a leap year.
Code: 
#include <iostream>
using namespace std;
int main(){
    int year;
    cout << "Enter the year: ";
    cin >> year;
    if (year%4==0 && year%100==0 && year%400==0)
        cout << "The year is Leap Year";
    else if (year%4==0 && year%100!=0)
        cout << "The year is Leap Year";
    else
        cout << "The year is not Leap Year";
}

Output: 
Enter the year: 2000
The year is Leap Year
Process returned 0 (0x0)   execution time : 1.645 s
Press any key to continue.


أحدث أقدم