C Program to Calculate Power using Recursion

Write a Program to Calculate Power using Recursion

//C Program to Calculate Power using Recursion

#include <stdio.h>

int Power(int base,int n)
{
	if(n != 0)
		return base * Power(base,n-1);
	else
		return 1;
}
int main()
{
	int base, n;
	printf("Enter Base Number :--> ");
	scanf("%d", &base);

	printf("Enter Power:--> ");
	scanf("%d", &n);

	int result = Power(base,n);

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

	return 0;
}

Output:

Enter Base Number :--> 5
Enter Power:--> 6
5^6 = 15625

≪ Previous | Next ≫