Recursiion string to integer

I want to understand the problem little bit more. As it states that have to take the string input in terms of integer and then
recursively convert that into integer.
So we pass the str as the parameter and accept the string then one by one i have to change the data type of each element?

hey @Vikaspal, you have to take input string as char string not as integer and then convert that char string into a number.
like let str=“1234” then your number will be (s[0]-‘0’)*1000+(s[1]-‘0’)*100+(s[2]-‘0’)*10+(s[3]-‘0’)=1234.

@sdevwrat why we are minus ‘0’ in each index value?

Is this zero or character value ?

@Vikaspal it is char ‘0’. this is used to convert char digits into integer digits.

hey @Vikaspal if still have any doubts let me know else please mark this doubt as resolved. Thankyou

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.

1 Like