Note that there are some explanatory texts on larger screens.

plurals
  1. POTransforming a 3x3 two-dimensional array in a 6x6 symmetrical two-dimensional array
    primarykey
    data
    text
    <p>I'm trying to solve an exercise that requires:</p> <p>- fill randomly a 3x3 two-dimensional array</p> <p>- transform the array in a second one with dimension 6x6:</p> <p>1&nbsp 2&nbsp 3&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp1&nbsp 2&nbsp 3 &nbsp3 &nbsp2&nbsp 1&nbsp</p> <p>4&nbsp 5&nbsp 6&nbsp&nbsp&nbsp&nbsp&nbsp-> 4&nbsp 5&nbsp 6 &nbsp 6 &nbsp5 4&nbsp </p> <p>7 &nbsp8&nbsp 9&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp7&nbsp 8&nbsp 9 &nbsp 9 &nbsp8&nbsp 7</p> <p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp7&nbsp 8&nbsp 9 &nbsp 9 &nbsp8 &nbsp7</p> <p> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 4&nbsp 5 &nbsp6 &nbsp 6&nbsp 5&nbsp 4</p> <p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp1&nbsp 2&nbsp 3 &nbsp 3&nbsp 2&nbsp 1</p> <p>I can't get it working tho' I think the logic must be right.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define DIM 3 int main() { int i, j, a[DIM][DIM],a1[DIM][DIM], a2[DIM][DIM], a3[DIM][DIM], b[2*DIM][2*DIM]; srand(time(NULL)); for (i = 0; i &lt; DIM; i++) { for (j = 0; j &lt; DIM; j++) { a[i][j] = rand() % 10; } } for (i = 0; i &lt; DIM; i++) { for (j = 0; j &lt; DIM; j++) { printf("%d ", a[i][j]); } printf("\n"); } for (i = 0; i &lt; DIM; i++) { for (j = 0; j &lt; DIM; j++) { a1[i][j] = a[i][DIM - 1 - j]; a2[i][j] = a[DIM - 1 -j][j]; a3[i][j] = a2[i][DIM - 1 - j]; if(i &lt; DIM &amp;&amp; j &lt; DIM) b[i][j] = a[i][j]; if(i &lt; DIM &amp;&amp; j &gt;= DIM) b[i][j] = a1[i][j]; if(i &gt;= DIM &amp;&amp; j &lt; DIM) b[i][j] = a2[i][j]; if(i &gt;= DIM &amp;&amp; j &gt;= DIM) b[i][j] = a3[i][j]; } } for (i = 0; i &lt; 2*DIM; i++) { for (j = 0; j &lt; 2*DIM; j++) { printf("%d ", b[i][j]); } printf("\n"); } return 0; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload