C++ Program to find x^n using recursion.

 Recursion program

* Recursion x^n program*

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int power(int x, int n)
{
if(n!=0){
return (x* power(x,n-1));
}
else 
return 1;
}
int main()
{
int a,pow;
cout<<"Enter the base and exponenent item\n";
cin>>a>>pow;
cout<<"The power of the "<<a<< "^"<<pow<<" is "<<power(a,pow);
return 0;
}

Comments

Popular posts from this blog

About RAM

Star Topology