• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 08, 2022 |2.2K Views
C++ Program to Display Armstrong numbers between 1 to 1000
Description
Discussion

In this video, we will see C++ Program to Display Armstrong numbers between 1 to 1000. A number “ N ” is an Armstrong number if “ N ” is equal to the sum of all N’s integers raised to the power of the number of integers in N.

A positive integer of n integers is called an Armstrong number of order n( order is number of integers) if,
abcd… = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ….

Examples:
1. Input number is 153.
= > 1 * 1 * 1+ 5 * 5 * 5+ 3 * 3 * 3 = 153
= > Output Yes, 153 is an armstrong number.

2. Input 120
= > 1 * 1 * 1 +2 * 2 * 2 +0 * 0 * 0 = 9
= > Output 120 isn't a Armstrong number.

3. Input 371
= > 3*3*3+ 7*7*7+1*1*1= 371
= > Output Yes 371 is an armstrong number.

Steps:
Step 1: Input the range from user i. e [1 to 1000].
Step 2: Find the total order( number of integers) of the given number.
Step 3: For each number, find the number raised to the power of o where o is the order calculated in Step 2.
Step 4: Compare the sum of all similar values with the given number.
Step 5: Print the figures which satisfy the condition in Step 4.

In this video, we generate the Armstrong number using a loop with a user-defined function. So a complete list of Armstrong numbers between 1 to 1000 are as follows:
1 2 3 4 5 6 7 8 9 153 370 371 407

Program for Armstrong numbers:
https://www.geeksforgeeks.org/program-for-armstrong-numbers/

Read More