int N;
cout << "N: " ;
cin >> N;
int sum=0;
int M=N ;
while (N>0)
{
int last = N % 10 ;
N = N%10;
sum = sum + pow(last, 3) ;
}
if(sum = M )
{
cout << "it's an armstrong" ;
}
else {
cout << "no";
}
return 0;
I got (sum == M) part,
I want to cube all the digits of the number and add them, if the sum = number then it’s an armstrong.
but after changing the Sum==M part, I checked for number 153 which is an armstrong but code is saying it’s not.
I copied your code and tested on my machine. It does say it’s armstrong
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cout << "N: " ;
cin >> N;
int sum=0;
int M=N ;
while (N>0)
{
int last = N % 10 ;
N = N/10;
sum = sum + pow(last, 3) ;
}
if(sum == M )
{
cout << "it's an armstrong" ;
}
else {
cout << "no";
}
return 0;
}