Respuesta :
Answer:
#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\n", userBase, userExponent, RaiseToPower(userBase, userExponent));
return 0;
}
Explanation:
Answer:
See the explanation
Explanation:
Note that, given a base number [tex]b[/tex] and and exponent [tex]e[/tex] we have that [tex]b^e[/tex] consists of multyplying b, e times. This means, to call the function e times of multiplying the result by b. Then consider the following code
int raise_to_power(int base, int exponent){
if exponent =0
then return 1
else
return base * raise_to_power(base,exponent-1)
}
Note that if base = 4 and exponent = 2
At first, we have that 2 is not 0, so it will multiply 4 times raise_to_power(4,1). But raise_to_power(4,1) will return 4 times raise_to_power(4,0). And raise_to_power(4,0)=1. So, the final result will be 4 * 4 * 1 = 16 which is de desired result.