How to resolve the algorithm Find the last Sunday of each month step by step in the Free Pascal 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 Free Pascal 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 Free Pascal programming language
Source code in the free programming language
program sundays;
Uses sysutils;
type
MonthLength = Array[1..13] of Integer;
procedure sund(y : Integer);
var
dt : TDateTime;
m,mm : Integer;
len : MonthLength;
begin
len[1] := 31; len[2] := 28; len[3] := 31; len[4] := 30;
len[5] := 31; len[6] := 30; len[7] := 31; len[8] := 31;
len[9] := 30; len[10] := 31; len[11] := 30; len[12] := 31; len[13] := 29;
for m := 1 to 12 do
begin
mm := m;
if (m = 2) and IsLeapYear( y ) then
mm := 13;
dt := EncodeDate( y, mm, len[mm] );
dt := EncodeDate( y, mm, len[mm] - DayOfWeek(dt) + 1 );
WriteLn(FormatDateTime('YYYY-MM-DD', dt ));
end;
end;
var
i : integer;
yy: integer;
begin
for i := 1 to paramCount() do begin
Val( paramStr(1), yy );
sund( yy );
end;
end.
You may also check:How to resolve the algorithm RCRPG step by step in the Phix programming language
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the ALGOL-M programming language
You may also check:How to resolve the algorithm Variable declaration reset step by step in the Perl programming language
You may also check:How to resolve the algorithm Menu step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Loops/For step by step in the Dart programming language