Leap Year Checker...even more to it
Colin Klipsch
cak3g at astsun9.astro.Virginia.EDU
Sun Sep 30 11:38:52 AEST 1990
In article <4404 at catfish11.UUCP> yedinak at motcid.UUCP (Mark A. Yedinak) writes:
>johnb at srchtec.UUCP (John Baldwin) writes:
>: (Stan Brown, Oak Road Systems) writes:
>
>:|In article <24700010 at sunc1>, mccaugh at 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 at virginia.edu | cause drowsiness. Use before 29-Feb.
____________________________/ \___________________________________________
More information about the Comp.lang.c
mailing list