basics · beginner · ~15 min
Use the exponent's recurrence b^e = b * b^(e-1).
Raise an integer to a non-negative power using recursion instead of a loop.
Implement long int_power(int base, int exp) that returns base raised to the power exp. Use recursion via the recurrence base^exp = base * base^(exp-1), with base^0 == 1 as the base case. No main — the grader calls it.
An int base and a non-negative int exp.
Returns base^exp as a long.
int_power(2, 10) -> 1024
int_power(3, 0) -> 1
int_power(5, 1) -> 5
exp == 0 returns 1 for any base.An int base and a non-negative int exp.
base raised to exp, as a long.
Must be recursive; base^0 == 1.
long int_power(int base, int exp) {
/* TODO */
return 1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.