C program to find nth power of a number using recursion

C program to find nth power of a number using recursion


Input:

Enter the number:
3
Enter n to find nth power of 3:
3

Output:

3th power of 3 is 27

Implementation:

#include <stdio.h>

int findnthpower(int n,int p)
{
 if(p<1)
  return 1;
 return n*findnthpower(n,p-1);
}

int main(void) {
 int n,x;
 printf("Enter the number:\n");
 scanf("%d",&x);
 printf("Enter n to find nth power of %d:\n",x);
 scanf("%d",&n);
 printf("%dth power of %d is %d",n,x,findnthpower(x,n));
 return 0;
}