How to resolve the algorithm Day of the week step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Day of the week step by step in the Fortran 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 Fortran programming language

Source code in the fortran programming language

PROGRAM YULETIDE
 
IMPLICIT NONE
  
INTEGER :: day, year
 
WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in"
DO year = 2008, 2121
   day = Day_of_week(25, 12, year)
   IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year
END DO
  
CONTAINS
 
FUNCTION Day_of_week(d, m, y)
   INTEGER :: Day_of_week, j, k, mm, yy
   INTEGER, INTENT(IN) :: d, m, y
  
   mm=m
   yy=y
   IF(mm.le.2) THEN
      mm=mm+12
      yy=yy-1
   END IF
   j = yy / 100
   k = MOD(yy, 100)
   Day_of_week = MOD(d + ((mm+1)*26)/10 + k + k/4 + j/4 + 5*j, 7)
END FUNCTION Day_of_week
  
END PROGRAM YULETIDE


  

You may also check:How to resolve the algorithm XML/Input step by step in the Oz programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Erlang programming language
You may also check:How to resolve the algorithm URL encoding step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Even or odd step by step in the jq programming language
You may also check:How to resolve the algorithm Prime numbers whose neighboring pairs are tetraprimes step by step in the Julia programming language