C Program to Check Armstrong Number

To understand this example, you should have the knowledge of the following C programming topics:


A positive integer is called an Armstrong number (of order n) if

abcd... = an + bn + cn + dn + 

In the case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because

153 = 1*1*1 + 5*5*5 + 3*3*3 

Check Armstrong Number of three digits

Output

Enter a three-digit integer: 371
371 is an Armstrong number.

Check Armstrong Number of n digits

Output

Enter an integer: 1634
1634 is an Armstrong number.

In this program, the number of digits of an integer is calculated first and stored in n. And, the pow() function is used to compute the power of individual digits in each iteration of the second for loop.