In number theory, a few numbers are termed as Armstrong Numbers in view of quite interesting behaviors that numbers exhibit. This blog addresses the basics of Armstrong number for absolute beginners in the programming domain and for those who are interested in learning new aspects. So let's get started…
As per number theory, A number for any given number base can be defined as an Armstrong number when it returns the same number itself on the summation of the digits of the number each raised to the number of digits in the number.
Armstrong number is also known as Narcissistic number or plus perfect number.
Let XYZ.. be a natural number with n digits and the number base be 10 (decimal number system) which is the commonly used number system. Other number systems can be binary with base 2, ternary with base 3, octal with base 8, and so on. To know more about the number system visit The number system.
Is XYZ.. an Armstrong number?
XYZ..can be considered as an Armstrong number if and only if
XYZ.. = Xn + Yn + zn +.... => XYZ..
Here the number 153 is a 3 digit number in the decimal number system.
Base 10 numbering calculation is:
= 1 x 102 + 5 x 101 +3 x 100?
= 1 x 100 + 5 x 10 + 3 x 1
= 100 + 50 + 3
= 153
Now let's check if 153 is an Armstrong number or not. For that, we use the above formula with n equals 3.
= 13 + 53 + 33
= (1 x 1 x 1)+(5 x 5 x 5)+(3 x 3 x 3)
= 1 + 125 +27
= 153
In both cases, we got the same digit on LHS and RHS. Thus we can prove that 153 is an Armstrong number with a base of 10.
Base 3 numbering calculation is:
= 1 x 32 + 2 x 32 +2 x 30
=1 x 9 +2 x 3 + 2 x 1
= 9 + 6 + 1
= 17
Now let's check if 122 is an Armstrong number or not in the base system 3. For that we use the above formula with n equals to 3.
= 13 + 23 + 23
= (1 x 1 x 1)+(2 x 2 x 2)+(2 x 2 x 2)
= 1 + 8 + 8
= 17
In both cases, we got 17 as the result and thus we prove that 122 is an Armstrong number with base 3.
From both examples, we can infer that an Armstrong number always exhibits the same property irrespective of the number system.
Check out our Armstrong programs in different programming languages.