Test cases not satisfied although output is correct
@Yuganshu,
you have to print “true” and “false” instead of “Yes” and “No”.
Also use long in your code.
Also, in the below code you are destroying N, hence you cannot use it further. store N in another variable and then use it for extraction of digits.
while (N > 0) {
digits++;
N = N / 10;
}
Suggested approach:
- Take input of number.
- Calculate the number of digits of the number in a variable say , cnt.
- Extract digit one by one from the number(using % 10).
- Raise it to the power of number of digits and add it to sum.
- After the loop check if the sum is equal to the original number.
- If yes, print true
- otherwise, print false.
1 Like
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.