Armstrong Number

Armstrong Number

C Language

What is Armstrong number?

let's describe it with an example:

371 --> 3-digit number.
so --> its ORDER is three.

371 is an Armstrong number because:
371 --> order 3.
and:
(3x3x3)+(7x7x7)+(1x1x1) = 371


How to check for #ARMSTRONG ?

1- How many digits?

2- Multiply each digit ( n times ) and add them.

3- If after calculation equal original --> #ARMSTRONG.


How many digits pseudocode :

count = 0
while(q != 0)
q = q/10
count++
return(count); //number of digits!


Multiply each digit (n times) and add them pseudocode :

// n = number of digits.

int count, res = 0, q, rem;
q while(q != 0)
rem = q%10
res = res + rem^n
q = q/10