Usetutoringspotscode to get 8% OFF on your first order!

  • time icon24/7 online - support@tutoringspots.com
  • phone icon1-316-444-1378 or 44-141-628-6690
  • login iconLogin

Write a recursive method called power that takes a double x and an integer n and that returnsxn.

Write a recursive method called power that takes a double x and an integer n and that returns xn.

Hint: a recursive definition of this operation is x n = x·xn−1. Also, remember that anything raised to the zeroed power is 1.

Optional challenge: you can make this method more efficient, when n is even, using xn = (xn/2)2.

 

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes