#include <stdio.h>
long power (int num, int pow)
{
if(pow)
{
return (num * power(num, pow - 1)); ///until pow=0; this function call it self
}
return 1;
}
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); ///calling the function
printf("
%d^%d is %ld", num, pow, result);
printf("
");
return 0;
}
Output
Enter a number: 2
Enter it's power: 5
2^5 is 32
Add your comment