How to resolve the algorithm Disarium numbers step by step in the bc programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Disarium numbers step by step in the bc programming language
Table of Contents
Problem Statement
A Disarium number is an integer where the sum of each digit raised to the power of its position in the number, is equal to the number.
135 is a Disarium number: 11 + 32 + 53 == 1 + 9 + 125 == 135 There are a finite number of Disarium numbers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Disarium numbers step by step in the bc programming language
Source code in the bc programming language
define is_disarium (num) {
n = num
sum = 0
len = length(n)
while (n > 0) {
sum += (n % 10) ^ len
n = n/10
len -= 1
}
return (sum == num)
}
count = 0
i = 0
while (count < 19) {
if (is_disarium(i)) {
print i, "\n"
count += 1
}
i += 1
}
quit
You may also check:How to resolve the algorithm Letter frequency step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the E programming language
You may also check:How to resolve the algorithm Infinity step by step in the Clojure programming language
You may also check:How to resolve the algorithm Guess the number/With feedback (player) step by step in the R programming language
You may also check:How to resolve the algorithm Determinant and permanent step by step in the Julia programming language