Is Year Leap
- Posted by Larry Gregg <lgregg at BIG12.METROBBS.COM> Jan 17, 1997
- 1115 views
Is a year a leap year? The following Euphoria function will tell you. I converted the original C routine to Euphoria. It is interesting to note that the year 2000 will be a leap year. Larry Gregg -- SNIP ---------------------------------------------------------------- global function isyearleap(integer year) -- Returns 1 if year is a leap year, 0 otherwise. -- Source: "Practical Algorithms for Programmers" -- By: Andrew Binstock and John Rex if not remainder(year,4) = 0 then -- if year not difisible by 4 return 0 -- it's not leap end if if year < 1582 then -- all years divisible by 4 were return 1 -- leap prior to 1582 end if if remainder(year,100) != 0 then -- if year divisible by 4, return 1 -- but not by 100, its leap end if if not remainder(year,400) = 0 then -- if year divisible by 100, return 0 -- but not by 400, it's not leap else return 1 -- if divisible by 400, it's leap end if end function -- SNIP ---------------------------------------------------------------- -- And to exercise the function: integer year, rc year = 1581 rc = isyearleap(year) printf(1,"\nYear=%4d, is leap year? %1d",year&rc) year = 1582 rc = isyearleap(year) printf(1,"\nYear=%4d, is leap year? %1d",year&rc) year = 1949 rc = isyearleap(year) printf(1,"\nYear=%4d, is leap year? %1d",year&rc) year = 1964 rc = isyearleap(year) printf(1,"\nYear=%4d, is leap year? %1d",year&rc) for i = 1200 to 2100 by 100 do year = i rc = isyearleap(year) printf(1,"\nYear=%4d, is leap year? %1d",year&rc) end for