Question

write a recursive method power( base, exponent )that , when called returns base exponent for example...

write a recursive method power( base, exponent )that , when called returns

base exponent

for example , power (3,4) 3*3*3*3*. assume that exponent is an integer greater than or equal to 1. Hint: the resursion step should use the relationship

base exponent = basec . base exponent. -1

and the terminating condition occurs when exponent is equal to 1, because base1 = base

Incroprate this method into a program that enables the user to enter the base and exponent

0 0
Add a comment Improve this question Transcribed image text
Answer #1
double power(double base, int exponent){
   //If exponent is negative
   if(exponent < 0){
      return 1.0/power(base, -1*exponent);
   }
   //If exponent is zero
   else if(exponent == 0){
      return 1;
   }
   //If exponent is positive
   else{
      //recursive call
      return base*power(base,exponent-1);
   }
}

Add a comment
Know the answer?
Add Answer to:
write a recursive method power( base, exponent )that , when called returns base exponent for example...
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
ADVERTISEMENT