Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Recursion. Write code to complete RaiseToPower(). Sample output if userBase i

ID: 642393 • Letter: 1

Question

1) Recursion.

  Write code to complete RaiseToPower(). Sample output if userBase is 4 and userExponent is 2 is shown below. Note: This example is for practicing recursion; a non-recursive function, or using the built-in function pow(), would be more common.

#include <stdio.h>

int RaiseToPower(int baseVal, int exponentVal){
int resultVal = 0;

if (exponentVal == 0) {
resultVal = 1;
}
else {
resultVal = baseVal * /* Your solution goes here */;
}

return resultVal;
}

int main(void) {
int userBase = 0;
int userExponent = 0;

userBase = 4;
userExponent = 2;
printf("%d^%d = %d ", userBase, userExponent, RaiseToPower(userBase, userExponent));

return 0;
}

Explanation / Answer

RaiseToPower(baseVal, exponentVal-1)

That complete line reads like this:

resultVal = baseVal * RaiseToPower(baseVal, exponentVal-1);