calculate if year is leap year

Solutions on MaxInterview for calculate if year is leap year by the best coders in the world

showing results for - "calculate if year is leap year"
Leni
22 Jul 2020
1if (i%4==0 && i%100!=0 || i%400==0) {
2months[2] = 29;
3}
4else {
5month[2] = 28;
6}
Tom
30 May 2016
1#include <iostream>
2using namespace std;
3
4int main() {
5    int year;
6    cout << "Enter a year: ";
7    cin >> year;
8    if (year % 4 == 0) {
9        if (year % 100 == 0) {
10            (year % 400 == 0) ?
11            cout << year << " is a leap year." :
12            cout << year << " is not a leap year.";
13        }
14        else
15            cout << year << " is a leap year.";
16    }
17    else
18        cout << year << " is not a leap year.";
19    return 0;
20}
similar questions
queries leading to this page
calculate if year is leap year