Generate Armstrong Numbers in C++
To generate Armstrong numbers in C++ programming, you have to ask to the user to enter the interval to print the Armstrong number
between the given interval as shown here in the following program.
C++ Programming Code to Generate Armstrong Numbers
Following C++ program ask to the user to enter the interval, to print the Armstrong numbers in the given interval.
Since if you start from 1 then the first Armstrong number will be 153.
So enter the interval which contain 153 like enter starting number as 1, 2, 3, 4...... etc.
and enter the ending number like 154, 155, 156.......etc. It is just a clue that the first Armstrong number is 153 so to check/print, you can follow it.
Generate Armstrong number from the following C++ program, so following C++ program illustrates it:
#include <iostream>
using namespace std;
int main()
{//
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"; }return 0;}