title: Incorrect output of matrix in C++
body: <p>I am writing a code to take a value and create a matrix with a size that allows for a pyramid of 1s to be made so the top one is at the x-1 element. For example, if the input was five, the output would be:</p>
  
  <pre><code>0 0 0 0 1 0 0 0 0
  0 0 0 1 0 1 0 0 0
  0 0 1 0 0 0 1 0 0
  0 1 0 0 0 0 0 1 0
  1 0 0 0 0 0 0 0 1
  </code></pre>
  
  <p>The problem is the code is generating values that shouldn't be one, or it is not outputting the matrix the correct way.  I have tried adding a cout to the code where it defines some values as 1 and those are correct, so I believe that the problem is in the output. For example, an input of x will give </p>
  
  <pre><code>0 0 0 0 1 0 0 0 1 
  0 0 0 1 0 1 0 1 0 
  1 0 1 0 0 0 1 0 0 
  0 1 0 0 0 1 0 1 0 
  1 0 1 0 0 0 0 0 1
  </code></pre>
  
  <p>The code is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
          cout &lt;&lt; "Matrix size:";
          int x;
          cin &gt;&gt; x;
          int arr1[2*x][x];
          for (int initialX=0; initialX&lt;x; initialX++){
                  for (int initialY=0; initialY&lt;=((2*x)-2); initialY++){
                          arr1[initialX][initialY]=0;
                  }
          }
          for (int set=0; set&lt;x; set++){
                  arr1[set][x-1-set]=1;
                  arr1[set][x-1+set]=1;
          }
          for (int outX=0; outX&lt;x; outX++){
                  for (int outY=0; outY&lt;(2*x-1); outY++){
                          cout &lt;&lt; arr1[outX][outY] &lt;&lt; " ";
                  }
                  cout &lt;&lt; endl;
          }
          return 0;
  }
  </code></pre>
  
  <p>This is my first time working with matrices in c++, so any help concerning matrices is appreciated. Also, if it's of any importance I'm using c++11.  Thank you in advance.</p>