This program calculates the power of a number using recursion.

To understand this example, you should have the knowledge of following C programming topics:

```
#include <stdio.h>
int power(int n1, int n2);
int main()
{
int base, powerRaised, result;
printf("Enter base number: ");
scanf("%d",&base);
printf("Enter power number(positive integer): ");
scanf("%d",&powerRaised);
result = power(base, powerRaised);
printf("%d^%d = %d", base, powerRaised, result);
return 0;
}
int power(int base, int powerRaised)
{
if (powerRaised != 0)
return (base*power(base, powerRaised-1));
else
return 1;
}
```

**Output**

Enter base number: 3 Enter power number(positive integer): 4 3^4 = 81

You can also compute power of a number using loops.

If you need to calculate the power of a number raised to a decimal value, you can use pow() library function.

It takes a lot of effort and cost to maintain Programiz. We would be grateful if you support us by either:

**Disabling AdBlock on Programiz. We do not use intrusive ads.**

or

Donate on Paypal
By using Programiz, you agree to use cookies as stated in our Privacy policy Continue