Write a program to find the power of x raised to n that is: x^n , using recursive function.

First time here? Checkout the FAQ!

x

#include <conio.h>

int power(int n1, int n2);

int main() {

int base, a, result;

//clrscr();

printf("Enter base number: ");

scanf("%d", &base);

printf("Enter power number(positive integer): ");

scanf("%d", &a);

result = power(base, a);

printf("%d^%d = %d", base, a, result);

getch();

return 0;

}

int power(int base, int a) {

if (a != 0)

return (base * power(base, a - 1));

else

return 1;

}