WAP to calculate power of base using recursion.


#include<iostream>
#include<conio.h>

using namespace std;

long int power (float b,int p);
int main()
{
float x;
int y;
cout<<"Enter the base value : ";cin>>x;
cout<<"\nEnter the power value : ";cin>>y;
cout<<"\n\nThe "<<x<<" to the power "<<y<<" is "<<power(x,y);
getch();
return(0);

}

long int power (float b,int p)
{
if(p==0)
return(1);
else
return(b*power(b,(p-1)));
}

No comments:

Post a Comment