Hi Greg, > The rule for leap years is: > > Every year that is exactly divisible by four is a leap year, except > for years that are exactly divisible by 100, but these centurial years > are leap years if they are exactly divisible by 400. For example, the > years 1700, 1800, and 1900 are not leap years, but the year 2000 is.
> I don't have my copy of K&R close to hand, but my preferred implementation > for a function that decides leap years is (pseudo-code): > > bool isleapyear (int year) { > if (year % 400 == 0) return true; > if (year % 100 == 0) return false; > if (year % 4 == 0) return true; > return false; > } Except, I think it should be in reverse order because now 2000 first gets a true, then a false but then a true again and after that EVERYTHING gets a false ;-) So, in pseudo code bool isleapyear (int year) { return false; if (year % 4 == 0) return true; if (year % 100 == 0) return false; if (year % 400 == 0) return true; } The funny thing is, a lot of people I taught programming in the 80's and 90's knew about the 4 year rule but not the exceptions. But programming it like that would work for however long that program would be around anyway. I know all of the programs I wrote commercially have been superseded by something else now, so it did not matter that I did it correctly. ;-) Bonno Bloksma