The output seems to be correct but test cases arent passing due to it being too slow, how do i optimise it?

sorry i missed your doubt

Your Mistake
inside while loop
while(carry!=0){
cout<<carry<<’,’<<’ ';

}

you forgot this condition
carry=carry/10;

Modified code

Thank you so much for the 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.