Find the last Sunday of each month: Difference between revisions
Content added Content deleted
(Fixed order (Free Pascal, FreeBASIC)) |
(Added XPL0 example.) |
||
Line 5,014: | Line 5,014: | ||
2020-11-29 |
2020-11-29 |
||
2020-12-27 |
2020-12-27 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func WeekDay(Year, Month, Day); \Return day of week (0=Sun, 1=Mon ... 6=Sat) |
|||
int Year, Month, Day; \works for years from 1583 onward |
|||
[if Month<=2 then [Month:= Month+12; Year:= Year-1]; |
|||
return rem((Day-1 + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400)/7); |
|||
]; |
|||
int Year, Month, LastDay, WD; |
|||
[Year:= IntIn(8); \from command line |
|||
for Month:= 1 to 12 do |
|||
[LastDay:= WeekDay(Year, Month+1, 1) - WeekDay(Year, Month, 28); |
|||
if LastDay < 0 then LastDay:= LastDay + 7; |
|||
LastDay:= LastDay + 27; \ = number of days in Month |
|||
WD:= WeekDay(Year, Month, LastDay); |
|||
LastDay:= LastDay - WD; |
|||
IntOut(0, Year); ChOut(0, ^-); |
|||
if Month < 10 then ChOut(0, ^0); IntOut(0, Month); ChOut(0, ^-); |
|||
IntOut(0, LastDay); CrLf(0); |
|||
]; |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
2013-01-27 |
|||
2013-02-24 |
|||
2013-03-31 |
|||
2013-04-28 |
|||
2013-05-26 |
|||
2013-06-30 |
|||
2013-07-28 |
|||
2013-08-25 |
|||
2013-09-29 |
|||
2013-10-27 |
|||
2013-11-24 |
|||
2013-12-29 |
|||
</pre> |
</pre> |
||