This C program checks an input number whether it is an Armstrong number on not and prints the results. An Armstrong number is special number sum of the nth power of its every digit is equal to the original number. The n is the number of digits in the input number. This concept is explained in more detail in the problem section.
We compiled the program using Dev C++ version 4 compiler installed on Windows 7 64-bit. You can use a different compiler if you like after modifying the source code according to your compiler specifications. This is necessary to compile an error-free program.
You must be familiar with following C programming concept to understand this example.
What is an Armstrong Number?
Suppose there is a number N, this number has n digits, if
- We take each digit of the number N separately
- Compute nth power of each digit, and
- Take the sum, S of all the power obtained in step 2.
- If the sum is equal to original number, N;
- Then the given number N is an Armstrong number.
The number N in above example is 371 and number of digits n = 3. So we raise each of the digits of 371 to power to 3. Then the sum of all power is equal to the original number if the number is an Armstrong number.