In this program, we are going to share a C++ program to generate Armstrong numbers. If you are a beginner and want to start learning the C++ programming, then keep your close attention in this tutorial as I am going to share a program for C++ program to generate Armstrong numbers.
To increase your C++ knowledge, practice all C++ programs:
Copy the below C++ program and execute it with the help of GCC compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<iostream.h> #include<conio.h> void main() { clrscr(); int num1, num2, i, n, rem, temp, count=0; //enter the interval (enter the two number) cout<<"Enter Starting Number : "; cin>>num1; cout<<"Enter Ending Number : "; cin>>num2; for(i=num1+1; i<num2; i++) { temp=i; n=0; while(temp!=0) { rem=temp%10; n = n + rem*rem*rem; temp=temp/10; } if(i==n) { if(count==0) { cout<<"Armstrong numbers between the given interval are : \n"; } cout<<i<<" "; count++; } } if(count==0) { cout<<"Armstrong number not found between the given interval"; } getch(); } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.