The other answer is perfectly correct, but will not compile with g++ - this is a modified version that will:
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
int a,b=0,sum=0;
long int n, store;
cout <<"Enter the Number. : ";
cin >> n;
store = n;
for(;n>0;)
//counts the digits
{
a=n%10;
n=n/10;
b++;
}
for(;n>0;)
{
a=n%10;
sum=sum+pow(a,b);
n=n/10;
}
if(sum==n)
{
cout << store << " is an Armstrong number" << endl;
return 0;
}
else
{
cout << store << " is not an Armstrong number << endl;
return 0;
}
}
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
int a,b=0,sum=0;
long int n, store;
cout <<"Enter the Number. : ";
cin >> n;
store = n;
for(;n>0;)
//counts the digits
{
a=n%10;
n=n/10;
b++;
}
for(;n>0;)
{
a=n%10;
sum=sum+pow(a,b);
n=n/10;
}
if(sum==n)
{
cout << store << " is an Armstrong number" << endl;
return 0;
}
else
{
cout << store << " is not an Armstrong number << endl;
return 0;
}
}