//Efficient code to find exponential(power) of given number using recursion.

#include<stdio.h>

#include<conio.h>

main()

{

int n,p;

int exp(int n,int p);

printf("Enter the number :");

scanf("%d",&n);

printf("Enter the power you want to compute :");

scanf("%d",&p);

printf("\n the term is %d",exp(n,p));

getch();

return 0;

}

int exp(int n,int p)

{

if(p==0)

return 1;

if(p%2==0)

return exp(n*n,p/2);

else

return (exp(n*n,p/2)*n);

}

#include<stdio.h>

#include<conio.h>

main()

{

int n,p;

int exp(int n,int p);

printf("Enter the number :");

scanf("%d",&n);

printf("Enter the power you want to compute :");

scanf("%d",&p);

printf("\n the term is %d",exp(n,p));

getch();

return 0;

}

int exp(int n,int p)

{

if(p==0)

return 1;

if(p%2==0)

return exp(n*n,p/2);

else

return (exp(n*n,p/2)*n);

}