How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
Generate the sequence a(n) when each element is the minimum integer multiple m such that the digit sum of n times m is equal to n.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the ALGOL 68 programming language
Source code in the algol programming language
BEGIN # find the smallest m where mn = digit sum of n, n in 1 .. 70 #
# returns the digit sum of n, n must be >= 0 #
OP DIGITSUM = ( INT n )INT:
IF n < 10 THEN n
ELSE
INT result := n MOD 10;
INT v := n OVER 10;
WHILE v > 0 DO
result +:= v MOD 10;
v := v OVER 10
OD;
result
FI # DIGITSUM # ;
# show the minimum multiples of n where the digit sum of the multiple is n #
FOR n TO 70 DO
BOOL found multiple := FALSE;
FOR m WHILE NOT found multiple DO
IF DIGITSUM ( m * n ) = n THEN
found multiple := TRUE;
print( ( " ", whole( m, -8 ) ) );
IF n MOD 10 = 0 THEN print( ( newline ) ) FI
FI
OD
OD
END
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the PL/I programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Delphi programming language
You may also check:How to resolve the algorithm Comments step by step in the Axe programming language
You may also check:How to resolve the algorithm Calkin-Wilf sequence step by step in the J programming language