/***************************************************
Program to calculate the power using recursion
*
* Enter base: 2
* Enter exponent: 5
* 2^5 = 32
***************************************************/
#include<stdio.h> // include stdio.h library
int power(int, int);
int main(void)
{
int base, exponent;
printf("Enter base: \n");
scanf("%d", &base);
printf("Enter exponent: \n");
scanf("%d", &exponent);
printf("%d^%d = %d", base, exponent, power(base, exponent));
return 0; // return 0 to operating system
}
int power(int base, int exponent)
{
//base condition
if(exponent == 0)
{
return 1;
}
else
{
// recursive call
return base * power(base, exponent - 1);
}
}