0
What is the formula of knowing if it is a leap year or not?
3 Answers
+ 4
Year is leap when:
(year % 4 == 0 and year % 100 !=0) or year % 400 == 0
+ 1
a leap year is a year that can be divided by 4 except for century years that aren't divisible by 400. So
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
this would do it
0
If you were to use a JavaScript function:
function isLeapYear (y) {
return (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0));
}
This function would return true if the year value passed in to the argument "y" is a leap year and otherwise false.
The above formula is based on the following rules:
1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4. The year is a leap year (it has 366 days).
5. The year is not a leap year (it has 365 days).