Be the first user to complete this post

  • 0
Add to List
Beginner

429. Find all the Armstrong numbers in the given range

Objective: Given a range of integers, wrote a program to find all the Armstrong numbers in that range.

What is Armstrong number: Determine the number of digits in the number. Call that n. Then take every digit in the number and raise it to the n power. Add all those together, and if your answer is the original number then it is an Armstrong number.

Example: 

low =1000, high = 10000
Output: 1634, 8208, 9474
Low = 100, high = 1000 Output: 152, 370, 371, 407

Approach: 

Earlier in the article check, if the given number is Armstrong number or not we have seen how to check if the given number is Armstrong. We will use the same logic here, iterate through all the numbers from low to high and for each number check if that is Armstrong, If yes then print it else move to the next number.

Output:

Armstrong number:153
Armstrong number:370
Armstrong number:371
Armstrong number:407