Task

Determine whether a given year is a leap year in the Gregorian calendar.



See also

 Leap year (wiki)


 
rem  - compute p mod q
function mod(p, q = integer) = integer
end = p - q * (p/q)
 
rem - return true (-1) if y is a leap year, otherwise 0
function isleapyear(y = integer) = integer
end = mod(y,4)=0 and mod(y,100)<>0 or mod(y,400)=0
 
rem - exercise the function
var y = integer
 
print "Test of century years"
for y = 1600 to 2000 step 100
   if isleapyear(y) then
     print y;" is a leap year"
   else
     print y;" is NOT a leap year"
next y
 
print "Test of current half-decade"
for y = 2015 to 2020
   if isleapyear(y) then
     print y; " is a leap year"
   else
     print y; " is NOT a leap year"
next y
 
end
 