Power Function (Exponentiation), Recursively

The goal for this exercise is to practice writing (increasingly complex) recursive code.

 

For this exercise, you need to implement the PowR method in the provided RecursiveMethods class. 

This class should be found in the Student_Answers.cs file.  The method should take two integer parameters named B and E, and will return the value of BE.  (for example, PowR(2,3) = 8, PowR(3,2) = 9, etc) You're not allowed to simply call the built-in Math.Pow method, and return the value, though – you need to find a way, by adjusting the values that you pass to the successive recursive calls, to get this to happen.  You only need to make this work for non-negative, whole numbers. 

Make sure that your code does the right thing for positive numbers, zero, and negative numbers for both the base and the exponent.  If a particular value (such as a negative exponent) doesn’t make sense (or is outside the scope of this exercise), your PowR method should catch that error, and then return 0.

What you need to do for this exercise: 

  1. Implement PowR, as described above
  2. Since this exercise isn't a Hand-In (nor a Required) exercise you don't need to make any tests pass.
    HOWEVER
    There are tests available for it (in the NUnit_Tests_Recursive_Power class).  This class is currently commented out, but if you want to run those tests you can un-comment the these tests.