Note that there are some explanatory texts on larger screens.

plurals
  1. PORotating 2D array for 45 degree
    text
    copied!<p>I have a matrix with possible sizes of 3x3 &amp; 5x5 &amp; 7x7 and I want to rotate it 45 degree.</p> <p>For example, this can be my matrix:</p> <pre><code>5 7 3 4 6 1 2 6 4 7 4 3 5 1 7 5 2 3 4 8 1 6 4 8 7 </code></pre> <p>The result should be this:</p> <pre><code>3 4 6 7 7 7 6 4 1 8 5 2 5 4 7 1 3 2 3 8 4 5 1 6 4 </code></pre> <p>code:</p> <pre><code>{ int MatrixSize; cout&lt;&lt;"Enter Matrix's Size:"&lt;&lt;endl; cin&gt;&gt;MatrixSize; while(!(MatrixSize == 3 || MatrixSize == 5 || MatrixSize == 7)) { cout&lt;&lt;"Invalid Matrix Size! Try Again:"&lt;&lt;endl; cin&gt;&gt;MatrixSize; } srand (time(NULL)); int Matrix[7][7]; for(int i = 0;i&lt;MatrixSize;i++) for(int j=0;j&lt;MatrixSize;j++) Matrix[i][j] = rand() % 9 + 1; for(int i = 0;i&lt;MatrixSize;i++) { for(int j=0;j&lt;MatrixSize;j++) cout&lt;&lt;Matrix[i][j]&lt;&lt;" "; cout&lt;&lt;endl; } cout&lt;&lt;endl; int Result[7][7]; for(int i = 0;i&lt;MatrixSize;i++) { for(int j=0;j&lt;MatrixSize;j++) { bool upperCorner = false; if(i &gt;= j) { upperCorner = true; } //the outer round should be rotated for MatrixSize/2 and for every round you go near to center in decreses with 1 until u reach the center and no rotation would be needed int round = min(i,j); int AmountToChange = MatrixSize - round; if(round == i) { if(upperCorner) { } } Result[desti][destj] = Matrix[i][j]; } } for(int i = 0;i&lt;MatrixSize;i++) { for(int j=0;j&lt;MatrixSize;j++) cout&lt;&lt;Result[i][j]&lt;&lt;" "; cout&lt;&lt;endl; } cout&lt;&lt;endl; </code></pre>
 

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