Exercise 1:
Write a C program to find power of any number using recursion.
Example:
Input any number: 5
Input power: 2
Output: 25
Solution:
#include <stdio.h>
int findPower(int n, int p);
int main()
{
int num, pow;
printf("Enter Any Number: ");
scanf("%d", &num);
printf("Enter Power: ");
scanf("%d", &pow);
printf("Result: %d\n", findPower(num, pow));
return 0;
}
int findPower(int n, int p)
{
if(p==0)
{
return 1;
}
else
{
return n * findPower(n, p-1);
}
}