title: swap rows matrix C++
body: <p>hello I have a problem with my program, i wanna swap rows in matrix with the next structure:</p>
  
  <p>first and last row.</p>
  
  <p>second and second to last row.</p>
  
  <p>until N to N values.</p>
  
  <p>Note: I used <code>#define n 4</code> but i need to be able to do it for any value of n.</p>
  
  <p>Input:</p>
  
  <pre><code>3 4 5 0
  2 6 1 2
  2 7 1 2
  2 1 1 2
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>2 1 1 2
  2 7 1 2
  2 6 1 2
  3 4 5 0
  </code></pre>
  
  <p>This program only changes the first and the last row:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  #define n 4 
  
  void interchange(int m[][n])
  {
      int rows = n;
  
  
      for (int i = 0; i &lt; n; i++)
      {
          int t = m[0][i];
          m[0][i] = m[rows - 1][i];
          m[rows - 1][i] = t;
      }
  }
  
  
  int main()
  {
  
      int m[n][n] = {
          { 8, 9, 7, 6 },
          { 4, 7, 6, 5 },
          { 3, 2, 1, 8 },
          { 9, 9, 7, 7 }
      };
  
      interchange(m);
  
  
      for (int i = 0; i &lt; n; i++)
      {
          for (int j = 0; j &lt; n; j++)
              cout &lt;&lt; m[i][j] &lt;&lt; " ";
          cout &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>thanks.</p>