What is the Armstrong Number?
An Armstrong number is a special kind of number in math.
It is equal to the sum of it's digits, each raised
to the power of the number of digits in the number.
For example, there are three digits in the number 153. It is
an Armstrong number because 1^3 + 5^3 + 3^3 equals 153.
Armstrong Number Algorithm
To find out if a number is an Armstrong number:
- Take the number and separate its digits. For example, if we have
the number 153, we get the digits 1, 5, and 3.
- Next, raise each digit to a power equal to the total number of
digits in the original number. In this case, there are three digits,
so we raise each digit to the power of 3: 1^3, 5^3, and 3^3.
- Now, calculate the result of each of these raised digits:
1^3 = 1, 5^3 = 125, and 3^3 = 27.
- Finally, add up these results: 1 + 125 + 27 = 153.
If the sum of the calculated results equals the original
number (153), then that number is an Armstrong
number.
FYI
In number theory, a narcissistic number in a given number base is
a number that is the sum of its own digits each raised to the power
of the number of digits.
Wikipedia
Armstrong numbers are narcissistic numbers.
Project #1
Create and interactive program that:
- Displays a definition of an Armstrong number
- Loop
- ask the user to enter an integer number
- if nothing is entered, exit the loop
- verify the users input
- calculate the number's value using the algorithm above
- is it an Armstrong number?
For simplicity use a menu.
Project #2
Convert the program to use a GUI.
Project #3
Write a program to find (if any) the number of Armstrong
number in the first 200 integers in base 2, 8, 10, and 16.
Display the base, the number of numbers found,
and each number found.
Display each Armstrong number found in
base 2, 8, 10, and 16?