1 suppose you buy a budget-priced pocket pc and discover that the chip inside can't do multiplication, only addition. you program your way out of this quandary by writing a recursive method, mult(), that performs multiplication of x and y by adding x to itself y times. its arguments are x and y and its return value is the product of x and y. write such a method and a main() program to call it. does the addition take place when the method calls itself or when it returns?

Respuesta :

/* Works only if a >= 0 and b >= 0 */ int pow(int a, int b) {  if (b == 0)  return 1;  int answer = a;  int increment = a;  int i, j;  for(i = 1; i < b; i++)  {  for(j = 1; j < a; j++)  {  answer += increment;  }  increment = answer;  }  return answer; }   /* driver program to test above function */ int main() {  printf("\n %d", pow(5, 3));  getchar();  return 0; }