How to resolve the algorithm Narcissistic decimal number step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Narcissistic decimal number step by step in the XPL0 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 XPL0 programming language
Source code in the xpl0 programming language
func IPow(A, B); \A^B
int A, B, T, I;
[T:= 1;
for I:= 1 to B do T:= T*A;
return T;
];
int Count, M, N, Sum, T, Dig;
[Text(0, "0 ");
Count:= 1;
for M:= 1 to 9 do
for N:= IPow(10, M-1) to IPow(10, M)-1 do
[Sum:= 0;
T:= N;
while T do
[T:= T/10;
Dig:= rem(0);
Sum:= Sum + IPow(Dig, M);
];
if Sum = N then
[IntOut(0, N); ChOut(0, ^ );
Count:= Count+1;
if Count >= 25 then exit;
];
];
]
You may also check:How to resolve the algorithm Copy a string step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Arrays step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Additive primes step by step in the Phix programming language