Data Structure Analysis: Two-dimensional arrays are used for Matrix storage. However, to store the converted matrix, two-dimensional arrays must be defined for storage because the rows and columns cannot be equal.
Question Analysis: The key lies in column-to-column conversion. First, the rows in the original matrix are converted to converted columns. The columns in the original matrix are converted to converted rows and must be rotated 90 degrees, therefore, after the original row is converted into a column, the value should be mac_row-row-1, mac_row is the total number of rows in the original matrix, and row is the row where the element to be converted is located, since row starts from 0, we need to subtract 1.
#include <iostream>#define MAC_ROW 3#define MAC_COL 4using namespace std;int main(){//define original matrix and set default value 0int OriMatrix[MAC_ROW][MAC_COL] = {0};//define converted matirxint ConvMatrix[MAC_COL][MAC_ROW] = {0};int elem = 0;//initialint row = 0;for(; row < MAC_ROW; row++){for(int col = 0; col < MAC_COL; col++){cin>>elem;OriMatrix[row][col] = elem;ConvMatrix[col][MAC_ROW - row - 1] = OriMatrix[row][col];}}//cout original matrixrow = 0;cout<<"original matrix:"<<endl;for(; row < MAC_ROW; row++){for(int col = 0; col < MAC_COL; col++){cout<<OriMatrix[row][col]<<"\t";}cout<<endl;}//cout converted matrixcout<<"converted matrix:"<<endl;row = 0;for(; row < MAC_COL; row++){for(int col = 0; col < MAC_ROW; col++){cout<<ConvMatrix[row][col]<<"\t";}cout<<endl;}system("pause");return 1;}