title: Creating fractal pattern using recursion
body: <p>I am trying to create this fractal pattern using recursion.</p>
  
  <pre><code>*
  * *
    *
  * * * *
      *
      * *
        *
  * * * * * * * *
          *
          * *
            *
          * * * *
              *
              * *
                *
  </code></pre>
  
  <p>The function that I need to implement is this:</p>
  
  <pre><code>void pattern(ostream&amp; outs, unsigned int n, unsigned int i);
   // Precondition: n is a power of 2 greater than zero.
   // Postcondition: A pattern based on the above example has been
   // printed to the ostream outs. The longest line of the pattern has
   // n stars beginning in column i of the output. For example,
   // The above pattern is produced by the call pattern(cout, 8, 0).
  </code></pre>
  
  <p>So far, this is what I have:</p>
  
  <pre><code>void pattern(ostream&amp; outs, unsigned int n, unsigned int i){
  
      if (n == 1){
          outs &lt;&lt; "*"&lt;&lt;endl;
      }
  
      else{
          pattern(outs, n / 2, i + 1);
          for (int k = 0; k &lt; n; k++){
              outs &lt;&lt; "* ";
  
          }
          outs&lt;&lt;endl;
  
  
          for (int k = 0; k &lt; i; k++){
              outs &lt;&lt; ' ';
          }
  
          pattern(outs, n / 2, i + 1);
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p>My code outputs what should be outputted, but the amount of spaces is off. How can I fix it?</p>