Test cases error

there are 2 test cases which upon processing gives wrong output. please help with the code

Hello @Amzad-Choudhary-353751958569219,

Please share your code.

#include
using namespace std;

int main() {
int no;
cin>>no;
int ans=0;
int a;
a=no;
while(a>0)
{
int last_dgt=a%10;
a=a/10;
ans=ans+(last_dgtlast_dgtlast_dgt);

}
if(ans==no)
cout<<"True"<<endl;
else
cout<<"False"<<endl;
return 0;

}

Hello @Amzad-Choudhary-353751958569219,

The formula you are using is wrong:
ans=ans+(last_dgtlast_dgt*last_dgt);

Reason:
You are adding the square of the digits irrespective of the number of digits in the number.
Solution:
Rather add the digit^(no. of digits in the number) i.e. the the digit raised to power the number of digits in the number.
Suggestion:
Refer to the examples given in the question.

Hope, this would help.
Give a like if you are satisfied.

i have written the correct formula but here when i pasted the code it is not showing *

#include
using namespace std;

int main() {
int no;
cin>>no;
int ans=0;
int a;
a=no;
while(a>0)
{
int last_dgt=a%10;
ans=ans+(last_dgtlast_dgtlast_dgt);
a=a/10;
}
if(ans==no)
cout<<“True”<<endl;
else
cout<<“False”<<endl;
return 0;
}

Hello @Amzad-Choudhary-353751958569219,

Share your code using coding blocks ide.
STEPS:

  1. paste your code at https://ide.codingblocks.com/
  2. Save it there.
  3. Share the URL generated.

can u tell where is the url. I have saved it

in custom input i had input the test cases 401 and 406 on which it is giving wrong on submitting but in custom input the same input are giving correct answer

Hello @Amzad-Choudhary-353751958569219,

It would be similar like: https://ide.codingblocks.com/s/200178
The link on the top of the webpage:

Hello @Amzad-Choudhary-353751958569219,

  1. Your code will work only for armstrong number of 3 digits.

  2. Output format is incorrect.
    True should be true
    and False should be false.

Correct code:

Hope, this would help.

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.