title: Recursion solution for a number raised to an exponent
body: <p>Hey I have a problem were I have to solve x^n in a number of ways. One of them involves using a recursion formula and its giving me a hard time. So one of the ways I used recursion for x^n for n>=0</p>
  
  <pre><code>int power2(int base, int power){
      if (power == 0)
          return 1;
      else if ( power == 1)
          return base;
      else 
          return (base * power2(base, power - 1));
  }
  </code></pre>
  
  <p>this makes sense to me So when i set X = 2 and N = 4, it is decreasing the power, which is acting as a counter, and doing 2x2 power raised to 3, 4*2, power raised to 2, 8 *2 = 16. Than the power is raised to 1, and I have a base case were if the power is raised to 1 it just returns base. However for my next one I have to solve it using three formulas.</p>
  
  <ul>
  <li>x<sup>0</sup> = 1</li>
  <li>x<sup>n</sup> if n is even = [x<sup>n/2</sup>]<sup>2</sup></li>
  <li>x<sup>n</sup> if n is odd = x * [x<sup>n/2</sup>]<sup>2</sup></li>
  </ul>
  
  <p>So what I have so far is</p>
  
  <pre><code>int power3(int base, int power){
      if(power == 0){
          return 1;
      }
      else if ( power == 1)
          return base;
      // if power is even
      if (power % 2 == 0){
          return base*(power3(base,(power/2)));
      }
      // if power is odd
      else{
          return 0;
      }
  }
  </code></pre>
  
  <p>So im just trying to get even numbers to work first, and when I set x=2 and n=4 it returns 8. Which makes sense to me, since when the power is 4/2 will only loop twice for being >1. So i really am trying to figure out a way to get this to loop one more time while staying true to the formula I was given.and when I added the odd base case now the program will work up untill n^5 but n^6 returns 32 </p>