How to resolve the algorithm Last Friday of each month step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Last Friday of each month step by step in the Delphi programming language
Table of Contents
Problem Statement
Write a program or a script that returns the date of the last Fridays 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 Last Friday of each month step by step in the Delphi programming language
Source code in the delphi programming language
program LastFridayOfMonth;
{$APPTYPE CONSOLE}
uses
System.SysUtils, System.DateUtils;
var
Year: Word;
Month: Word;
D1: TDateTime;
D2: Word;
begin
Write('Enter year: ');
ReadLn(Year);
for Month := MonthJanuary to MonthDecember do begin
D1 := EndOfAMonth(Year, Month);
D2 := DayOfTheWeek(D1);
while D2 <> DayFriday do begin
D1 := IncDay(D1, -1);
D2 := DayOfTheWeek(D1);
end;
WriteLn(DateToStr(D1));
end;
end.
You may also check:How to resolve the algorithm Factors of an integer step by step in the HicEst programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Elena programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Factor programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the Ruby programming language
You may also check:How to resolve the algorithm Compiler/virtual machine interpreter step by step in the Aime programming language