How to resolve the algorithm Count in factors step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Count in factors step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
Write a program which counts up from 1, displaying each number as the multiplication of its prime factors. For the purpose of this task, 1 (unity) may be shown as itself.
2 is prime, so it would be shown as itself. 6 is not prime; it would be shown as
2 × 3
{\displaystyle 2\times 3}
. 2144 is not prime; it would be shown as
2 × 2 × 2 × 2 × 2 × 67
{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Count in factors step by step in the ALGOL 68 programming language
Source code in the algol programming language
OP +:= = (REF FLEX []INT a, INT b) VOID:
BEGIN
[UPB a + 1] INT c;
c[:UPB a] := a;
c[UPB a+1:] := b;
a := c
END;
PROC factorize = (INT nn) []INT:
BEGIN
IF nn = 1 THEN (1)
ELSE
INT k := 2, n := nn;
FLEX[0]INT result;
WHILE n > 1 DO
WHILE n MOD k = 0 DO
result +:= k;
n := n % k
OD;
k +:= 1
OD;
result
FI
END;
FLEX[0]INT factors;
FOR i TO 22 DO
factors := factorize (i);
print ((whole (i, 0), " = "));
FOR j TO UPB factors DO
(j /= 1 | print (" × "));
print ((whole (factors[j], 0)))
OD;
print ((new line))
OD
You may also check:How to resolve the algorithm Xiaolin Wu's line algorithm step by step in the Pascal programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Sorting algorithms/Radix sort step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm List comprehensions step by step in the C programming language
You may also check:How to resolve the algorithm Comments step by step in the PostScript programming language