title: Swap Rows for Columns in C++
body: <p>I am having some trouble trying to change rows by columns.</p>
  
  <p>All I want is change rows and columns of a static 2D array (3x3). I don't want to just simply print the array with reverse indexes. I tried to store the value of the actual position in the array in <strong>int aux</strong> but there is no effect. </p>
  
  <p>Input:</p>
  
  <pre><code>1 2 3 
  4 5 6
  7 8 9
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1 4 7
  2 5 8
  3 6 9
  </code></pre>
  
  <p>With this code, the result is the same 2D array. I can't see the problem, can you help me?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std; 
  
  int main ()
  {
      int vec[3][3];
      int x, y, aux;
  //Input
      for(x=0; x&lt;3;x++)
  {
      for(y=0; y&lt;3;y++)
      {
      cout &lt;&lt; "POSITION ["&lt;&lt;x+1&lt;&lt;"]["&lt;&lt;y+1&lt;&lt;"]: ";
      cin &gt;&gt; vec[x][y];
      }
  }
  
      cout&lt;&lt;"\nPress ENTER...";
      cin.ignore();
      cin.get();
      system("CLS");
  //Array before the change
  cout&lt;&lt;"ARRAY A"&lt;&lt;endl;
  for(x=0; x&lt;3;x++)
  {
      for(y=0; y&lt;3;y++)
      {
      cout&lt;&lt;vec[x][y]&lt;&lt;"\t";
      }
  cout &lt;&lt; "\n";
  }
  //Change
  for(x=0; x&lt;3;x++)
  {
      for(y=0; y&lt;3;y++)
      {
          if(x!=y)
          {
              aux=vec[x][y];
              vec[x][y]=vec[y][x];
              vec[y][x]=aux;
          }
      }
  }
  
  //Array after the change
  cout&lt;&lt;"\nARRAY A"&lt;&lt;endl;
  for(x=0; x&lt;3;x++)
  {
      for(y=0; y&lt;3;y++)
      {
      cout&lt;&lt;vec[x][y]&lt;&lt;"\t";
      }
  cout &lt;&lt; "\n";
  }
  cout &lt;&lt; "\n";
  system("PAUSE");
  return 0;
  }
  </code></pre>