How to resolve the algorithm Find the last Sunday of each month step by step in the Seed7 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 Seed7 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 Seed7 programming language
Source code in the seed7 programming language
$ include "seed7_05.s7i";
include "time.s7i";
include "duration.s7i";
const proc: main is func
local
var integer: weekday is 1; # 1 for monday, 2 for tuesday, and so on up to 7 for sunday.
var integer: year is 0;
var integer: month is 1;
var time: aDate is time.value;
var time: selected is time.value;
begin
if length(argv(PROGRAM)) <> 2 then
writeln("usage: lastWeekdayInMonth weekday year");
writeln(" weekday: 1 for monday, 2 for tuesday, and so on up to 7 for sunday.");
else
weekday := integer parse (argv(PROGRAM)[1]);
year := integer parse (argv(PROGRAM)[2]);
for month range 1 to 12 do
aDate := date(year, month, 1);
while aDate.month = month do
if dayOfWeek(aDate) = weekday then
selected := aDate;
end if;
aDate +:= 1 . DAYS;
end while;
writeln(strDate(selected));
end for;
end if;
end func;
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the jq programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Maple programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the C# programming language
You may also check:How to resolve the algorithm Polyspiral step by step in the Wren programming language
You may also check:How to resolve the algorithm Quad-power prime seeds step by step in the Sidef programming language