Calculate power of a number program using recursion
/*C program to calculate power of any number using recursion*/
#include <stdio.h>
//function for calculating power
long int getPower(int b, int p)
{
long int result = 1;
if (p == 0)
return result;
result = b * (getPower(b, p - 1)); //call function again
}
int main()
{
int base, power;
long int result;
printf("Enter value of base: ");
scanf("%d", &base);
printf("Enter value of power: ");
scanf("%d", &power);
result = getPower(base, power);
printf("%d to the power of %d is: %ld\n", base, power, result);
return 0;
}
Output
Enter value of base: 10
Enter value of power: 4
10 to the power of 4 is: 10000
Calculate power of a number program using recursion
Output
need an explanation for this answer? contact us directly to get an explanation for this answer