Answer:
/*
Program to computea number raised to a power using recursion
base = number and exp is the power to which the number is raised
*/
#include <stdio.h>
int power(int base, int exp);
int main(){
int base, exp;
printf("Enter base: ");
scanf("%d", &base);
printf("Enter exponent: ");
scanf("%d", &exp);
long result = power(base,exp); //function call
printf("%d raised to the power %d = %ld\\", base, exp, result);
return 0;
}
int power(int base, int exp){
//2 base cases
// if exp = 0, return 1
if (exp == 0){
return 1;
}
//if exp 1, return base
if ( exp == 1){
return base;
} //base case when expnent is 0
//otherwise return base * base to the power exp-1
return base * power(base, exp-1 );
}
Step-by-step explanation: