Example 30: Armstrong Numbers

Learn how to print Armstrong numbers.

Problem

If the sum of cubes of each digit of the number is equal to the number itself, the number is called an Armstrong number. For instance,

153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )

Write a program to print out all Armstrong numbers between 1 and 500.

Examples

Input Output
Nil 1 153 370 371 407

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Get hands-on with 1400+ tech skills courses.