Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 17:01
Show Gist options
  • Save nalin-adh/30a30eebd71eaac046e9 to your computer and use it in GitHub Desktop.
Save nalin-adh/30a30eebd71eaac046e9 to your computer and use it in GitHub Desktop.
A C++ program 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)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment