C++

# Program to display Armstrong number between two intervals in C++ In this article, you’ll learn to print Armstrong number program between two number in C++ language or up to N terms with more example in detail.

Q: what is Armstrong number

Ans: A number is Armstrong number if only if “The digit number equal to the sum of the powers of their digit. For example 1,153,1634 etc.

• 1^3+5^3+3^3=153 is an Armstrong number.
• 1^4+6^4+3^4+4^4=1634 is an Armstrong number.

Q: Write a program in C++ language to display all Armstrong number between 1 to 500 on the screen.

Solution:

 #include using namespace std; int main() { int n,r,x,s; cout<<“Armstrong number are: “; for(n=1;n<=500;n++){   s=0; x=n; while(x!=0){ r=x%10; s=s+r*r*r; x=x/10; } if(s==n) printf(“%d “,n); } return 0; }

 The output of this program: Armstrong number are: 1 153 370 371 407

Q: Write a program in C++ language to display all Armstrong number between 1 to 1000 on the screen.

Solution:

 #include using namespace std; int main() { int n,r,x,s; cout<<” Armstrong number are: “; for(n=1;n<=1000;n++){   s=0; x=n; while(x!=0){ r=x%10; s=s+r*r*r; x=x/10; } if(s==n) printf(“%d “,n); } return 0; }

 The output of this program: Armstrong number are: 1 153 370 371 407

Q: Write a program in C++ language to display all Armstrong number between 1000 to 10000 on the screen.

Solution:

 #include using namespace std; int main() { int n,r,x,s; cout<<“Armstrong number are: “; for(n=1000;n<=10000;n++){   s=0; x=n; while(x!=0){ r=x%10; s=s+r*r*r*r; x=x/10; } if(s==n) printf(“%d “,n); } return 0; }

 The output of this program: Armstrong number are: 1634 8208 9474

Q: Write a program in C++ language to display all Armstrong number between 10000 to 100000 on the screen.

Solution:

 #include using namespace std; int main() { int n,r,x,s; cout<<“Armstrong number are: “; for(n=10000;n<=100000;n++){   s=0; x=n; while(x!=0){ r=x%10; s=s+r*r*r*r*r; x=x/10; } if(s==n) printf(“%d “,n); } return 0; }

 The output of this program: Armstrong number are: 54748 92727 93084

You may also learn the following programming: