A number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 3^3 + 7^3 + 1^3 = 371. Some other armstrong numbers are: 0, 1, 153, 370, 407.
Armstrong number C codeBelow is the logic to detect if it is armstrong number. We extract each digit starting from LSB (right most). We divide the number by 10. Reminder is the digit in LSB and same time all the digits will be shifted to right. We calculate the cube of remainder and add to the sum. Now we repeat the same for the rest of the digits till we exhaust the digits. Now the sum contains the sum of all cube of digits. We compare this sum with the original number. A match means the number is armstrong number.
Enter an integer: 153 153 is an armstrong number.
Armstrong number series
Enter Max range: 15000 Printing armstrong numbers from 0 - 15000 0, 1, 153, 370, 371, 407,
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Learn on Youtube