How to resolve the algorithm Narcissistic decimal number step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Narcissistic decimal number step by step in the Ring programming language
Table of Contents
Problem Statement
A Narcissistic decimal number is a non-negative integer,
n
{\displaystyle n}
, that is equal to the sum of the
m
{\displaystyle m}
-th powers of each of the digits in the decimal representation of
n
{\displaystyle n}
, where
m
{\displaystyle m}
is the number of digits in the decimal representation of
n
{\displaystyle n}
.
Narcissistic (decimal) numbers are sometimes called Armstrong numbers, named after Michael F. Armstrong. They are also known as Plus Perfect numbers.
Generate and show here the first 25 narcissistic decimal numbers.
Note:
0
1
= 0
{\displaystyle 0^{1}=0}
, the first in the series.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Narcissistic decimal number step by step in the Ring programming language
Source code in the ring programming language
n = 0
count = 0
size = 15
while count != size
m = isNarc(n)
if m=1 see "" + n + " is narcisstic" + nl
count = count + 1 ok
n = n + 1
end
func isNarc n
m = len(string(n))
sum = 0
digit = 0
for pos = 1 to m
digit = number(substr(string(n), pos, 1))
sum = sum + pow(digit,m)
next
nr = (sum = n)
return nr
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Modula-2 programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Simula programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the Crystal programming language
You may also check:How to resolve the algorithm Same fringe step by step in the Java programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the Batch File programming language