Write a program or a script that returns the last Sundays of each month of a given year. The year may be given through any simple input method in your language (command line, std in, etc).

Example of an expected output:

./last_sundays 2013
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


Related tasks
 Day of the week
 Five weekends
 Last Friday of each month


 
@echo off
setlocal enabledelayedexpansion
set /p yr= Enter year: 
echo.
call:monthdays %yr% list 
set mm=1
for %%i in (!list!) do (
  call:calcdow !yr! !mm! %%i dow
  set/a lsu=%%i-dow
  set mf=0!mm!
  echo !yr!-!mf:~-2!-!lsu! 
  set /a mm+=1
)
pause
exit /b
 
:monthdays yr &list
setlocal
call:isleap %1 ly
for /L %%i in (1,1,12) do (
  set /a "nn = 30 + ^!(((%%i & 9) + 6) %% 7) + ^!(%%i ^^ 2) * (ly - 2)
  set list=!list! !nn!
)
endlocal & set %2=%list%
exit /b
 
:calcdow yr mt dy &dow  :: 0=sunday
setlocal
set/a a=(14-%2)/12,yr=%1-a,m=%2+12*a-2,"dow=(%3+yr+yr/4-yr/100+yr/400+31*m/12)%%7"
endlocal & set %~4=%dow%
exit /b
 
:isleap yr &leap  :: remove ^ if not delayed expansion
set /a "%2=^!(%1%%4)+(^!^!(%1%%100)-^!^!(%1%%400))"
exit /b
 