programming-examples/c/Recursion/C Program to find Power of a Number using Recursion.c

28 lines
514 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C Program to find Power of a Number using Recursion
*/
#include <stdio.h>
long power (int, int);
int main()
{
int pow, num;
long result;
printf("Enter a number: ");
scanf("%d", &num);
printf("Enter it's power: ");
scanf("%d", &pow);
result = power(num, pow);
printf("%d^%d is %ld", num, pow, result);
return 0;
}
long power (int num, int pow)
{
if (pow)
{
return (num * power(num, pow - 1));
}
return 1;
}