So, I wrote this program to check if a given number is an armstrong number or not. But when I ran this code with 153 as input (an armstrong) it shows "not armstrong", but when I ran it for other numbers like 370, 371 (armstrong numbers) it shows "Armstrong". Even more, when I ran it with an online compiler, it ran completely fine but on my laptop (using MinGW) it shows the error with 153. Here is the code (I have included the math.h file):
int n; cin>>n;
int sum=0;
int originaln=n;
while(n>0){
int lastdigit=n%10;
sum+= pow(lastdigit,3);
n=n/10;
}
if(sum==originaln){
cout<<"Armstrong"<<endl;
}
else{
cout<<"Not Armstrong"<<endl;
}
return 0;
Also, can someone tell why this code doesn't work for 4 digit numbers?