#include <iostream>#include <iomanip>using namespace STD;voidGrial (int(*a) [5],intN) {//Array rotates 90 degrees clockwise. //Boundary value Considerations Let me think for a little bit. intTempintStartX =0;intStarty =0;intj =0; while(StartX < n/2) {StartX = J; for(inti = j; I < n-j-1; i++) {starty = i;//Do not open space, just exchange data can be easily done. temp = A[startx][starty]; A[startx][starty] = A[n-starty-1][STARTX]; A[n-starty-1][STARTX] = a[n-startx-1][n-starty-1]; A[n-startx-1][n-starty-1] = A[starty][n-startx-1]; A[starty][n-startx-1] = temp; } j + +; }}intMain () {inta[][5] = {1,2,3,4,5,6,7,8,9,Ten, One, A, -, -, the, -, -, -, +, -, +, A, at, -, -}; Grial (A,5); for(inti =0; I <5; i++) { for(intj =0; J <5; J + +) {cout<< SETW (4) << A[i][j]; }cout<< Endl; }cout<< Endl;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Algorithm title: Matrix rotation 90 degrees