Trying to swap values in 2d array inside nested for loops
<p>I have been struggling with this for a while. Hopefully someone can help. Here goes. I have 2 dimensional array that is initialized in a nested for loop. If the dimensions of the array mod (%) 2 is even (d%2 == 0), I want to swap the element 2 and element 1 in the array matrix with one another. </p>

<p>Another idea I am struggling with is this, instead of perform a swap I could just simply explicit assign the 1 and 2 to the index of the array inside the for loop. </p>

<p>Here is the code I have so far.. I appreciate any inputs that will assist me to arriving at the right solution..</p>

<pre><code>if (d % 2 == 0)
{        
    for (row_i = 0; row_i &lt; d; row_i++)//loops through rows
    {
        for(col_j = 0; col_j &lt; d; col_j++) //loops through column
        {
            board[row_i][col_j] = multi_dim--;
            if(board[row_i][col_j] == 2 &amp;&amp; board[row_i][col_j] == 1)
            {
                int hold = board[d][d -2];
                board[d][d - 2] = board[d][d - 1];
                board[d][d - 1] = hold;
            }
            printf(" %2d ", board[row_i][col_j]);
        }
        printf("\n");  
    }
}
</code></pre>