How to resolve the algorithm Count in octal step by step in the ALGOL W programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Count in octal step by step in the ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin
string(12) r;
string(8) octDigits;
integer number;
octDigits := "01234567";
number := -1;
while number < MAXINTEGER do begin
integer v, cPos;
number := number + 1;
v := number;
% build a string of octal digits in r, representing number %
% Algol W uses 32 bit integers, so r should be big enough %
% the most significant digit is on the right %
cPos := 0;
while begin
r( cPos // 1 ) := octDigits( v rem 8 // 1 );
v := v div 8;
( v > 0 )
end do begin
cPos := cPos + 1
end while_v_gt_0;
% show most significant digit on a newline %
write( r( cPos // 1 ) );
% continue the line with the remaining digits (if any) %
for c := cPos - 1 step -1 until 0 do writeon( r( c // 1 ) )
end while_r_lt_MAXINTEGER
end.
You may also check:How to resolve the algorithm Ruth-Aaron numbers step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Sidef programming language
You may also check:How to resolve the algorithm Calendar step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Cramer's rule step by step in the zkl programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the BBC BASIC programming language