[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leap year algorithm needed



if(!(year % 400) || (!(year % 4) && (year %100))) thisyear=leapyear;

A2MG wrote:

> I believe you 'd do something like this in any language.  Others please correct
> me if I am wrong:
>
> Get or read the year
> Divide it by 400
> If there is no remainder (modulo, or decimal places), it is leap. Jump ahead to
> Test month. Example: 2000
> Divide year by 100
> If there is no remainder, it is a  nonleap century. Jump ahead to Test month.
> Example: 1900
> Divide year by 4
> If there's a remainder (modulo), it is not leap. Example: 1999
> If there is no remainder, it is leap.
>
> Test Month. If greater than 12 or less than 1, error.
>
> Test day in February (2).
> If greater than 29, error.
> If greater than 28, check year - must be leap, else error.
>
> Test day in other months. If 4,6,9,11, days must be less than 31.
>
> All other months are 31 days, but if you want to test them, they are
> 1,3,5,7,8,10,12.
>
> Others can play with that or make suggestions.
>
> Beverly Cadieux
> Join the Apple II Mail Group at http://members.aol.com/A2MG