How to resolve the algorithm Find the last Sunday of each month step by step in the Icon and Unicon 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 Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
procedure main(A)
every write(lastsundays(!A))
end
procedure lastsundays(year)
every m := 1 to 12 do {
d := case m of {
2 : if IsLeapYear(year) then 29 else 28
4|6|9|11 : 30
default : 31
} # last day of month
z := 0
j := julian(m,d,year) + 1 # first day of next month
until (j-:=1)%7 = 6 do z -:=1 # backup to last sunday (6)
suspend sprintf("%d-%d-%d",year,m,d+z)
}
end
link datetime, printf
You may also check:How to resolve the algorithm FASTA format step by step in the Kotlin programming language
You may also check:How to resolve the algorithm CRC-32 step by step in the Go programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the OCaml programming language
You may also check:How to resolve the algorithm JSON step by step in the Oz programming language