What is the formula of knowing if it is a leap year or not? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

What is the formula of knowing if it is a leap year or not?

20th Sep 2018, 5:31 PM
Kath
3 ответов
+ 4
Year is leap when: (year % 4 == 0 and year % 100 !=0) or year % 400 == 0
20th Sep 2018, 5:47 PM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 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
20th Sep 2018, 6:14 PM
Shadowa
Shadowa - avatar
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).
20th Sep 2018, 6:20 PM
Alex