How to resolve the algorithm Count in octal step by step in the Cowgol programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in octal step by step in the Cowgol programming language

Table of Contents

Problem Statement

Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number. Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count in octal step by step in the Cowgol programming language

Source code in the cowgol programming language

include "cowgol.coh";

typedef N is uint16; 

sub print_octal(n: N) is
    var buf: uint8[12];
    var p := &buf[11];
    [p] := 0;
    loop
        p := @prev p;
        [p] := '0' + (n as uint8 & 7);
        n := n >> 3;
        if n == 0 then break; end if;
    end loop;
    print(p);
end sub;

var n: N := 0;
loop
    print_octal(n);
    print_nl();
    n := n + 1;
    if n == 0 then break; end if; 
end loop;

  

You may also check:How to resolve the algorithm String interpolation (included) step by step in the JavaScript programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Fortran programming language
You may also check:How to resolve the algorithm Dot product step by step in the EasyLang programming language
You may also check:How to resolve the algorithm User input/Text step by step in the Elixir programming language
You may also check:How to resolve the algorithm Semordnilap step by step in the PowerShell programming language