title: C - matrix rotation
body: <p>I'm writing a program in C and I need a <code>M x N</code> matrix to rotate clockwise. I tried some algorithms, but they only work in <code>N x N</code> matrices. </p>
  
  <p>The matrix <code>{(1,4), (2,5), (3,6)}</code> should become <code>{(3,2,1), (6,5,4)}</code>:</p>
  
  <pre><code>1 4
  2 5  -&gt;  3 2 1
  3 6      6 5 4
  </code></pre>
  
  <p>I wrote this piece of code to transpose the matrix, and now I don't know how to swap the columns:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>void transpose(int matrix[MAX][MAX], int m, int n)
  {
      int transpose[MAX][MAX], d, c;
  
      for (c = 0; c &lt; m; c++)
        for( d = 0 ; d &lt; n ; d++)
           transpose[d][c] = matrix[c][d];
  
      for (c = 0; c &lt; n; c++)
          for(d = 0; d &lt; m; d++)
              matrix[c][d] = transpose[c][d];
  }</code></pre>
  </div>
  </div>
  </p>