How to resolve the algorithm Find the last Sunday of each month step by step in the Maple programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Find the last Sunday of each month step by step in the Maple programming language
Table of Contents
Problem Statement
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:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Find the last Sunday of each month step by step in the Maple programming language
Source code in the maple programming language
sundays := proc(year)
local i, dt, change, last_days;
last_days := [31,28,31,30,31,30,31,31,30,31,30,31];
if (Calendar:-IsLeapYear(year)) then
last_days[2] := 28;
end if;
for i to 12 do
dt := Date(year, i, last_days[i]);
change := 0;
if not(Calendar:-DayOfWeek(dt) = 1) then
change := -Calendar:-DayOfWeek(dt) + 1;
end if;
dt := Calendar:-AdjustDateField(dt, "date", change);
printf("%d-%d-%d\n", year, Month(dt), DayOfMonth(dt));
end do;
end proc;
sundays(2013);
You may also check:How to resolve the algorithm Discordian date step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Swift programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Delphi programming language
You may also check:How to resolve the algorithm Dijkstra's algorithm step by step in the jq programming language
You may also check:How to resolve the algorithm Sleeping Beauty problem step by step in the BASIC programming language