How to resolve the algorithm Digital root step by step in the Run BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Digital root step by step in the Run BASIC programming language
Table of Contents
Problem Statement
The digital root,
X
{\displaystyle X}
, of a number,
n
{\displaystyle n}
, is calculated: The additive persistence is the number of summations required to obtain the single digit. The task is to calculate the additive persistence and the digital root of a number, e.g.: The digital root may be calculated in bases other than 10.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Digital root step by step in the Run BASIC programming language
Source code in the run programming language
print "Digital root of 627615 is "; digitRoot$(627615, 10)
print "Digital root of 39390 is "; digitRoot$(39390, 10)
print "Digital root of 588225 is "; digitRoot$(588225, 10)
print "Digital root of 393900588225 is "; digitRoot$(393900588225, 10)
print "Digital root of 9992 is "; digitRoot$(9992, 10)
END
function digitRoot$(n,b)
WHILE n >= b
c = c + 1
n = digSum(n, b)
wend
digitRoot$ = n;" persistance is ";c
end function
function digSum(n, b)
WHILE n <> 0
q = INT(n / b)
s = s + n - q * b
n = q
wend
digSum = s
end function
You may also check:How to resolve the algorithm Pointers and references step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Compiler/virtual machine interpreter step by step in the Julia programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Tailspin programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Action! programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the OCaml programming language