Path: utzoo!attcan!uunet!wuarchive!julius.cs.uiuc.edu!psuvax1!rutgers!mcnc!uvaarpa!murdoch!astsun9.astro.Virginia.EDU!cak3g From: cak3g@astsun9.astro.Virginia.EDU (Colin Klipsch) Newsgroups: comp.lang.c Subject: Leap Year Checker...even more to it Summary: More complex than you think Message-ID: <1990Sep30.013852.8764@murdoch.acc.Virginia.EDU> Date: 30 Sep 90 01:38:52 GMT References: <1115.26ff47b6@iccgcc.decnet.ab.com> <242@srchtec.UUCP> <4404@catfish11.UUCP> Sender: news@murdoch.acc.Virginia.EDU Organization: University of Virginia Lines: 43 In article <4404@catfish11.UUCP> yedinak@motcid.UUCP (Mark A. Yedinak) writes: >johnb@srchtec.UUCP (John Baldwin) writes: >: (Stan Brown, Oak Road Systems) writes: > >:|In article <24700010@sunc1>, mccaugh@sunc1.cs.uiuc.edu writes: >:|> Ordinarily, a leap-year is a multiple of four, so that--given leap-year y-- >:|> (y%4 == 0) ought to indicate if y designates a leap-year. > >:|Bzzzzzt! Nope, but thanks for playing. Vanna has lovely gifts for you. To be nitpicky to the point of nausea, I will point out that the rule for deciding leap years has FOUR conditions, not three. A correct algorithm is: #define FALSE 0 #define TRUE 1 int is_leap_year(int year) { if (year%4000 == 0) return FALSE; else if (year%400 == 0) return TRUE; else if (year%100 == 0) return FALSE; else if (year%4 == 0) return TRUE; else return FALSE; } With the addition of the divisible-by-4000 condition, the Gregorian calendar is now accurate to one day in 20,000 years. (Assuming its term of use lasts long enough for the rule to be practiced, which I doubt!) Source: _Exploration of the Universe_, G. Abell -------------------------------------------------------------------------- "May the forces of evil become confused on the way to your house." -- George Carlin Bemusedly, | Disclaimers: Colin Klipsch | Not guaranteed to fulfill any purpose, Property of UVa Ast. Dept. | express or implied. Contents may have Charlottesville, Virginia | settled during shipping. Not rated. May cak3g@virginia.edu | cause drowsiness. Use before 29-Feb. ____________________________/ \___________________________________________