Day of the week: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,651: | Line 3,651: | ||
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067 |
/* 2011 2016 2022 2033 2039 2044 2050 2061 2067 |
||
2072 2078 2089 2095 2101 2107 2112 2118 */</lang> |
2072 2078 2089 2095 2101 2107 2112 2118 */</lang> |
||
=={{header|S-BASIC}}== |
|||
<lang BASIC> |
|||
$constant SUNDAY = 0 |
|||
rem - compute p mod q |
|||
function mod(p, q = integer) = integer |
|||
end = p - q * (p/q) |
|||
comment |
|||
return day of week (Sun = 0, Mon = 1, etc.) for a |
|||
given Gregorian calendar date using Zeller's congruence |
|||
end |
|||
function dayofweek (mo, da, yr = integer) = integer |
|||
var y, c, z = integer |
|||
if mo < 3 then |
|||
begin |
|||
mo = mo + 10 |
|||
yr = yr - 1 |
|||
end |
|||
else mo = mo - 2 |
|||
y = mod(yr,100) |
|||
c = int(yr / 100) |
|||
z = int((26 * mo - 2) / 10) |
|||
z = z + da + y + int(y/4) + int(c/4) - 2 * c + 777 |
|||
z = mod(z,7) |
|||
end = z |
|||
rem - main program |
|||
var year = integer |
|||
print "Christmas will fall on a Sunday in" |
|||
for year=2008 to 2121 |
|||
if dayofweek(12,25,year) = SUNDAY then |
|||
print year |
|||
next year |
|||
end |
|||
{{out}} |
|||
<pre>Christmas will fall on a Sunday in |
|||
2011 |
|||
2016 |
|||
2011 |
|||
2033 |
|||
2039 |
|||
2044 |
|||
2050 |
|||
2061 |
|||
2067 |
|||
2072 |
|||
2078 |
|||
2089 |
|||
2095 |
|||
2101 |
|||
2107 |
|||
2112 |
|||
2118</pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |