Initialize matrix
voidInitial_square_matrix (int* * * PM,intN) {pm[0] =New int*[n]; for(inti =0; I < n; i++) {pm[0][i] =New int[n]; for(intj =0; J < N; J + +) pm[0][I][J] = i * n + j +1; }}
Destroying matrices
void Destroy_square_matrix (intint n) { for (int0 ; I < n; i++) if (NULL! = pm[0][i] )Delete[] pm[0 ][i]; Delete [] pm[0]; pm[0] = NULL;}
Print matrix
voidPrint_square_matrix (int* * M,intN) {cout<<"------------------------------------"<<Endl; for(inti =0; I < n; ++i) { for(intj =0; J < N; J + +) cout<< M[i][j] <<"\ t"; cout<<Endl; }}
Rotate left to print
voidPrint_square_matrix_reversel90 (int* * M,intN) {cout<<"------------------------------------"<<Endl; for(inti =0; I < n; ++i) { for(intj =0; J < N; J + +) cout<< M[j][n-i-1] <<"\ t"; cout<<Endl; }}
Rotate Right to print
voidPrint_square_matrix_reverser90 (int* * M,intN) {cout<<"------------------------------------"<<Endl; for(inti =0; I < n; ++i) { for(intj =0; J < N; J + +) cout<< M[n-j-1][i] <<"\ t"; cout<<Endl; }}
A very special kind of rotation.
/* Only applies to matrices like this 1 2 3 4 (7 8 9 1011 ) 1516 2021 25*/
void Reverse_square_matrix (intint n) { for (int0 ; I < n; + + i) { for (int0; j < N; j + +) 1 1 ); }}
Test
1 intMN =5;2 int**m;3 4Initial_square_matrix (&M, MN);5 Print_square_matrix (M, MN);6 print_square_matrix_reversel90 (M, MN);7 print_square_matrix_reverser90 (M, MN);8 Reverse_square_matrix (M, MN);9 Print_square_matrix (M, MN);TenDestroy_square_matrix (&m, MN);
Matrix Rotation 90 degrees