Is Armstrong number

Please tell me the mistake in my code

include

include

using namespace std;

int countdigit(int n){
int j=0;

while(n!=0){
     n = n/10;
   j++;  
}

return j;
}

int arms(int n){
int num = 0;
int i;
while(n!=0){
i = n%10;
num += pow(i , countdigit(n));
n /= 10;
}
return num;
}

void checknum(int n){
int ans = arms(n);

if (n == ans)
{
    cout<<"True";
}
else
{
    cout<<"False";
}

}

int main(){
int n;
cin>>n;
checknum(n);
return 0;
}

@abhinavssr2003_eab0717682969e5c,
please check this ive commented and corrected the mistake : https://ide.codingblocks.com/s/657139

@abhinavssr2003_eab0717682969e5c, to pass test cases use long long and “true” “false” not starting with capital

but why we have to create one bucket temp?? why it is not running with n only??

@abhinavssr2003_eab0717682969e5c,
u have to keep the power equal to count of original no only

okay sure …i missed that part also

1 Like

can you give me an example of this?

@abhinavssr2003_eab0717682969e5c, which one? just dry run with 370,371 and 372 youll get it what was actually going wrong

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

ohh thank you…i got it

1 Like