矩阵转置,就是行变成列,列变成行,贴代码如下,仅供参考:
//
// 转置m行,n列的矩阵
//
void transpositionMatrix(int sourceMatrix[5][8], int destMatrix[8][5], int m, int n)
{
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
destMatrix[j][i] = sourceMatrix[i][j];
}
}
}
void main()
{
int matrix1[5][8] = {0};
int matrix2[8][5] = {0};
int value = 1;
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 8; ++j)
{
matrix1[i][j] = value++;
cout << matrix1[i][j] << " ";
}
cout << endl;
}
// 转置矩阵
transpositionMatrix(matrix1, matrix2, 5, 8);
for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 5; ++j)
{
matrix1[i][j] = value++;
cout << matrix2[i][j] << " ";
}
cout << endl;
}
system("pause");
}