How to resolve the algorithm Day of the week step by step in the ALGOL W programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Day of the week step by step in the ALGOL W programming language
Table of Contents
Problem Statement
A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).
In what years between 2008 and 2121 will the 25th of December be a Sunday? Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to y2k type problems.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Day of the week step by step in the ALGOL W programming language
Source code in the algol programming language
begin % find years where Christmas day falls on a Sunday %
integer procedure Day_of_week ( integer value d, m, y );
begin
integer j, k, mm, yy;
mm := m;
yy := y;
if mm <= 2 then begin
mm := mm + 12;
yy := yy - 1;
end if_m_le_2;
j := yy div 100;
k := yy rem 100;
(d + ( ( mm + 1 ) * 26 ) div 10 + k + k div 4 + j div 4 + 5 * j ) rem 7
end Day_of_week;
write( "25th of December is a Sunday in" );
for year := 2008 until 2121 do begin
integer day;
day := Day_of_week( 25, 12, year );
if day = 1 then writeon( I_W := 5, S_W := 0, year );
end for_year
end.
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Tcl programming language
You may also check:How to resolve the algorithm Dragon curve step by step in the Clojure programming language
You may also check:How to resolve the algorithm Nonoblock step by step in the C# programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the PL/0 programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Logo programming language