Some problems in recursion

Can you share the following codes:

  1. multilply two numbers without using * with the help of recursion
  2. convert a string into integer using recursion.
    I tried my best, but being a very slow and average guy, It’s very tough to get to the exact solution. please help… :(:frowning:

hello @Tiwary725

a) let say the two numbers are a and b.
then a*b= a+a + a + a + a + a … (b times)

mul(a,b) = a+mul(a,b-1)
base case if b=1 then return a.

b) if abcd is a string then we can write it as
intially ans=0;
convert(abcd,ans)=convert(bcd,ans*10+a)

base case if string is empty return ans;

I couldn’t understand the solution of string conversion problem. Please explain it in detail.

refer this -> https://www.geeksforgeeks.org/convert-a-string-to-an-integer-using-recursion/

why is ‘double’ written before x and y?

use int in place of that.
it wont make any difference.