How to resolve the algorithm Find the last Sunday of each month step by step in the Run BASIC 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 Run BASIC 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 Run BASIC programming language

Source code in the run programming language

input "What year to calculate (yyyy) : ";year
print "Last Sundays in ";year;" are:" 
dim month(12)
mo$ = "4 0 0 3 5 1 3 6 2 4 0 2"
mon$ = "31 28 31 30 31 30 31 31 30 31 30 31"

if year < 2100 then leap = year - 1900 else leap = year - 1904
m = ((year-1900) mod 7) + int(leap/4) mod 7
for n = 1 to 12
    month(n) = (val(word$(mo$,n)) + m) mod 7
    month(n) = (val(word$(mo$,n)) + m) mod 7
next
for n = 1 to 12
    for i = (val(word$(mon$,n)) - 6) to val(word$(mon$,n))
        x = (month(n) + i) mod 7 
        if x = 4 then print year ; "-";right$("0"+str$(n),2);"-" ; i
    next
next

  

You may also check:How to resolve the algorithm Loops/While step by step in the Julia programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the PL/I programming language
You may also check:How to resolve the algorithm XML/XPath step by step in the Racket programming language
You may also check:How to resolve the algorithm Largest proper divisor of n step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Janet programming language