Calculate one number raise to power another using recursion
#include<iostream>
#include<conio.h>
using namespace std;
int func_power(int base, int power);
int main()
{
int base_number = 0 , power = 0, temp = 0, result =
1;
cout
<< "\n\n\t ________Program to calculate one number
raise to another_______";
cout
<< "\n\n\n Enter the base number - ";
cin
>> base_number;
cout
<< "\n\n
Enter the power to be calculated - ";
cin
>> power;
result
= func_power(base_number, power);
cout
<< "\n\n\t Output - " << base_number
<< " raise to power "
<< power << " is "
<< result;
getch();
return 0;
}
int func_power(int base, int power)
{
if (power == 0)
{
return 1;
}
else
{
return base * func_power(base, power - 1);
}
}
No comments:
Post a Comment