check leap year

Solutions on MaxInterview for check leap year by the best coders in the world

showing results for - "check leap year"
Line
22 Jan 2021
1#include<iostream>
2using namespace std;
3int main() {
4   int year = 2016;
5   if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
6   cout<<year<<" is a leap year";
7   else
8   cout<<year<<" is not a leap year";
9   return 0;
10}
Johanna
19 Apr 2016
1if (i%4==0 && i%100!=0 || i%400==0) {
2months[2] = 29;
3}
4else {
5month[2] = 28;
6}
Layne
03 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}
Ozzy
03 Jan 2021
1if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
2cout<<year<<" is a leap year";
3else
4cout<<year<<" is not a leap year";
Jazmín
27 Apr 2017
1I'll simplfy this. Humans cut every year 6 hours short (1/4 of a day[it is
2actually less than 1/4 but see below for the rest]).
3This means that every 4 years, 24 hours have been lost and to make up for
4that, we just add the 24 hours to a much shorter month (like february - 28d)
5giving us the 'leap year' and making the year 1 day longer.
6
7
8This is to keep up with the astronomical years which the western calender
9is based off of, in which the terrarial 'lap' of the sun is the equivilant
10of 265.24 full rotations of the earth (day/night cycles). The reason we don't
11measure individual years in 365.24 earth rotations is because we would end up
12having a super long day at the end of the year and then days would end up
13being dark or light depending on the year and it would all get in a 
14big muddle. Instead, we keep the calendar normal and just remove the .24 of 
15a day off every 3 years, only to add all the lost time together and make
16another day every four years (or every leap year). You may have noticed
17that 4x0.24 is actually not 100 but 0.96, so surely after 100 years,
18we would miss a day? Well actually, in the year 2000, we did still have a leap
19year because it is a multiple of 400(a leap century if you will),
20but every other 100 years, we do not have an extra day because of that 0.24.
Maina
10 Jan 2020
1import calendar
2
3def is_leap(year):
4    return calendar.isleap(year)
5
similar questions
queries leading to this page
check leap year