Answer the question
In order to leave comments, you need to log in
How to come to such a decision?
Task: Find the number of leap years between two dates without using loops.
I decided by the "poke" method according to this formula. At least the outputs matched:
years = ((last_year / 4) % 100 + (last_year / 400)) - ((start_year / 4) % 100 + (start_year / 400));
Then I also looked at this solution, apparently it is more correct:
((last_year / 4) - (last_year / 100) + (last_year / 400)) - ((start_year / 4) - (start_year / 100) + (start_year / 400)) ;
I can’t understand how to come to such a decision logically, where is the relationship? Why divide by 4 first, then divide by 100, then add and subtract by 400?
If not laziness, please explain.
Answer the question
In order to leave comments, you need to log in
Read - https://ru.wikipedia.org/wiki/%D0%93%D1%80%D0%B8%D...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question