Skip to main content

Posts

Showing posts from November, 2016

Armstrong Number

            An Armstrong number is an  n -digit number that is equal to the sum of the  n th  powers of its digits. For example 153 is an Armstrong Number in 3 digit number 1 3  +  5 3  +  3 3   =  153 1  +125+27  =153 1634 is an Armstrong Number in 4 digit number 1 4  + 6 4  + 3 4  + 4 4  =  1634 1+1296+81+256=1634 And so numbers from 0-9 all are Armstrong Numbers as  0 1 is 0 , 1 1   is 1,   2 1 is 2 , 3 1 is 3 and so on..   Armstrong Algorithm Step1: Read a number.  Step2:  Store all the digits of a number in an array digits[] Step3:  Count all the digits of a number and store in variable   length Step4:  Start a loop till  the length of a number Step5: Raise each digit to a power equal to the number of digits in the number. For ex, each digit of a three‑digit number would be raised to the third power; each digit of a Seven‑digit number would be raised to the Seventh power; and so on Step6: Add the results to variable  sum