Question

Please write in C++ language: Create a recursive function called power that receives two positive int...

Please write in C++ language:

Create a recursive function called power that receives two positive int parameters that represent the base and exponent. The function should return the base raised to the exponent. Place the power's function prototype in power.hpp and its implementation in power.cpp. The main function already contains some code, but you need to complete the requirements that is described inside the file.

Sample Output: Enter a base: 5 Enter an exponent: 3 5 ^ 3 = 125

Sample Output #2: Enter a base: 2 Enter an exponent: 10 2 ^ 10 = 1024

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code:

#include <iostream>
using namespace std;
int power(int base,int exponent)
{
   if(exponent==0)
       return 1;
   return base*power(base,exponent-1);
}
int main()
{
int base,exponent;
   cout<<"Enter base:";
   cin>>base;
   cout<<"Enter exponent:";
   cin>>exponent;
   int result=power(base,exponent);
   cout<<base<<"^"<<exponent<<" ="<<result<<endl;
}

Sample input and output:

Add a comment
Know the answer?
Add Answer to:
Please write in C++ language: Create a recursive function called power that receives two positive int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT