How to convert parts of string to integer?

hello @ganesh2512

to convert string into integer u can use stoi function which u are already doing correctly.

this problem can be solved using pure string only.

check this->

Why do we add ‘0’ at the end? when we are subtracting n[i] from 9

to convert char to inter we subtact ‘0’ from it .

and to convert integer back to char we add ‘0’ to it.

here we are converting the difference(which is integer) back to char

Thankyou, I was confused on this concept since many years

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.