Home > Blockchain >  Recursive function in C that calculate the result of their multiplication
Recursive function in C that calculate the result of their multiplication

Time:11-14

I need to write a recursive function with 2 parameters that calculate the result of their multiplication by only using addition

exemple : mult(2,5)=>10

I wrote the function but I think that I'm missing something in the return

int mult(unsigned int num1, int num2) {
    if (num1 == 0) return 0;
    return mult(num1 - 1, num2);
}

CodePudding user response:

You should return:

    return num2   mult(num1 - 1, num2);
  • Related