How to resolve the algorithm Long year step by step in the Modula-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Long year step by step in the Modula-2 programming language

Table of Contents

Problem Statement

Most years have 52 weeks, some have 53, according to ISO8601.

Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Long year step by step in the Modula-2 programming language

Source code in the modula-2 programming language

MODULE LongYear;
FROM InOut IMPORT WriteCard, WriteLn;

VAR year: CARDINAL;

PROCEDURE isLongYear(year: CARDINAL): BOOLEAN;
    PROCEDURE p(year: CARDINAL): CARDINAL;
    BEGIN
        RETURN (year + year DIV 4 - year DIV 100 + year DIV 400) MOD 7;
    END p;
BEGIN
    RETURN (p(year) = 4) OR (p(year-1) = 3);
END isLongYear;

BEGIN
    FOR year := 2000 TO 2100 DO
        IF isLongYear(year) THEN
            WriteCard(year, 4);
            WriteLn;
        END;
    END;
END LongYear.


  

You may also check:How to resolve the algorithm Base64 decode data step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the Oz programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the D programming language
You may also check:How to resolve the algorithm Euler method step by step in the COBOL programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Wren programming language