A leap year is a year that has 29 days in the month of February. This is done to keep the calendar year the same as the astronomical year because astronomical years have a quarter of a day more than the calendar year. This is why a leap year occurs once every 4 years.
To see if a given year is a leap year, use the algorithm below:
If (year is not divisible by 4) then (it is a common year)
else if (year is not divisible by 100) then (it is a leap year)
else if (year is not divisible by 400) then (it is a common year)
else (it is a leap year)
#include <iostream>using namespace std;int main() {int year = 2020;if (year % 4 != 0)cout << year << " is a common year.";else if (year % 100 != 0)cout << year << " is a leap year.";else if (year % 400 != 0)cout << year << " is a common year.";elsecout << year << " is a leap year.";}
Free Resources