How to resolve the algorithm Digital root/Multiplicative digital root step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Digital root/Multiplicative digital root step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
The multiplicative digital root (MDR) and multiplicative persistence (MP) of a number,
n
{\displaystyle n}
, is calculated rather like the Digital root except digits are multiplied instead of being added:
Show all output on this page. The Product of decimal digits of n page was redirected here, and had the following description The three existing entries for Phix, REXX, and Ring have been moved here, under ===Similar=== headings, feel free to match or ignore them.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Digital root/Multiplicative digital root step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' FB 1.05.0 Win64
Function multDigitalRoot(n As UInteger, ByRef mp As Integer, base_ As Integer = 10) As Integer
Dim mdr As Integer
mp = 0
Do
mdr = IIf(n > 0, 1, 0)
While n > 0
mdr *= n Mod base_
n = n \ base_
Wend
mp += 1
n = mdr
Loop until mdr < base_
Return mdr
End Function
Dim As Integer mdr, mp
Dim a(3) As UInteger = {123321, 7739, 893, 899998}
For i As UInteger = 0 To 3
mp = 0
mdr = multDigitalRoot(a(i), mp)
Print a(i); Tab(10); "MDR ="; mdr; Tab(20); "MP ="; mp
Print
Next
Print
Print "MDR 1 2 3 4 5"
Print "=== ==========================="
Print
Dim num(0 To 9, 0 To 5) As UInteger '' all zero by default
Dim As UInteger n = 0, count = 0
Do
mdr = multDigitalRoot(n, mp)
If num(mdr, 0) < 5 Then
num(mdr, 0) += 1
num(mdr, num(mdr, 0)) = n
count += 1
End If
n += 1
Loop Until count = 50
For i As UInteger = 0 To 9
Print i; ":" ;
For j As UInteger = 1 To 5
Print Using "######"; num(i, j);
Next j
Print
Next i
Print
Print "Press any key to quit"
Sleep
You may also check:How to resolve the algorithm Prime decomposition step by step in the R programming language
You may also check:How to resolve the algorithm Summarize and say sequence step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Ol programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the Fortran programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the Groovy programming language