Drehen Sie 3 x 3 Matrix in C ++C++

Programme in C++. Entwicklerforum
Anonymous
 Drehen Sie 3 x 3 Matrix in C ++

Post by Anonymous »

Wie kann ich in CPP um 90 Grad eine 3 x 3 -Matrix drehen ... < /p>
//create the matrix
const int MATRIX_SIZE = 3;
int m[MATRIX_SIZE][MATRIX_SIZE];
int last = MATRIX_SIZE - 1;

int count = 0;
int level = 0;

for(int i =0; i< MATRIX_SIZE; i++)
{
for(int j = 0; j< MATRIX_SIZE; j++)
{
m[j] = count++;
}
}

//rotate matrix
for(int i = 0; i
Ich bekomme viele von 1 hinzugefügt und ich weiß nicht, woher sie kommen. < /p>
Ausgabe: < /p>
------ Original Matrix ------
0 1 2
3 4 5
6 7 8
------ Rotated Matrix ------
6 3 1
1 4 1
1 1 1
< /code>
Ich verwende "Level", um durch den inneren Teil der Matrix zu schwal. Gibt es eine andere Möglichkeit, dies mit STD zu tun?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post