Monday, February 24, 2014

Write a program to find x to the power of y using recursion


By on 3:43 AM

If we want to find x to the power of y using recursion then it can be done in this way.



#include <stdio.h>
#include <conio.h>
int power (int,int);
int main()
{
int x,y;
printf("enter the values of x and y");
scanf("%d%d",&x,&y);
result=power(x,y);
printf("the value of x to the power y is %d",result);
getch();
}
int power (int x,int y)
{
if (y==1)
return x;
else if(y==0)
return 1;
else
return(x*power(x,y-1);
}
view raw recursion hosted with ❤ by GitHub

About Authors

Aakash and Shreeram are owners of this website. Both are engineering student. Aakash is studying computer engineering and has passion with blogs and love to play with it while Shreeram is studying civil engineering and has dream of implementing technology in practical life.

0 comments :

Post a Comment