Write a function powerthree that, given a non-negative number n, returns 3n ( 3^n, or "3 raised topower n") recursively, assuming 3n is something that can be represented as an integer. do not use a loop, and do not use the character '*' anywhere in your code.

Respuesta :

tonb
Because the * is not to be used, you also have to create a recursive multiplication; it could look like this:

int times(int a, int b) {
  if (a == 1)
    return b;    else return b + times(a - 1, b);
}

int powerthree(int n) {
   if (n == 0)
      return 1;
   else return times(3, powerthree(n - 1));
}