Correct expression for checking leap years

Posted by Debanjan on Stack Overflow See other posts from Stack Overflow or by Debanjan
Published on 2010-06-12T16:58:17Z Indexed on 2010/06/12 17:12 UTC
Read the original article Hit count: 189

Filed under:
|

What will be the exact definition of leap year? AFAIK "A year which is divisible by 4 is a leap year. But for century years' the years which are divisible by 400 is a leap year."

But that definition makes 100, 200, 300, 400.... upto 1700 NOT LEAP years! But in Gregorian calendar all of them are all leap year, check this out.

You can also try "call 1700" in Linux to verify.

So the correct algorithm for leap years would be:

if ( (year % 4 == 0) && ( year <= 1700 || year % 100 != 0 || year % 400 == 0 ))
    printf("%d is a leap year.\n", year);
 else
    printf("%d is not a leap year.\n", year);

But is this specific to Gregorian calendar? Even if that is the case why is it not mentioned here?

Regards,

PS:The history of Gregorian callender seems interesting check out the September month of 1752.

© Stack Overflow or respective owner

Related posts about calendar

Related posts about leap-year