sir/mam, I have doubt in the way string is converted into integer.
can you please explain how you have used
ans=ans+((s[i])-‘0’)*p)
for conversion.
In the function where string is converted to integer
hello @vageesha
note to convert numreic character to integer we subtract ‘0’ from that numeric character.
for example to convert ‘2’ into 2 . we do ‘2’-‘0’ =2
if 123 is the number then we can write this as 1 * 10^2 + 2 * 10 +3 right?
string to int function is doing the same thing.
if string is “123”
then first it is adding 3 to answer .[ (‘3’-‘0’) * 1 = 3]
and then it is adding 20 to the answer [ (‘2’-‘0’ )*10 = 20 ]
and then 100 [ (‘1’-‘0’)*100 = 100 ]
and the end result is 123.