用二维数组作为函数参数,实现矩阵转置。按如下函数原型编程计算并输出m×n阶矩阵的转置矩阵。其中,m和n的值由用户从键盘输入。已知m和n的值都不超过10。 void Transpose(int a[][N], int at[][M], int m, int n); void InputMatrix(int a[][N], int m, int n); void PrintMatrix(int at[][M], int n, int m); 输入提示信息:"Input m, n:" "Input %d*%d matrix:\n" 输入格式:"%d,%d" 输出提示信息和格式:"The transposed matrix is:\n" 输出格式(输完矩阵的一行要换行):"%d\t"
时间: 2024-02-27 16:52:55 浏览: 80
好的,我明白了。以下是代码实现:
```c++
#include <iostream>
using namespace std;
const int N = 10, M = 10;
void InputMatrix(int a[][N], int m, int n);
void Transpose(int a[][N], int at[][M], int m, int n);
void PrintMatrix(int at[][M], int n, int m);
int main()
{
int m, n;
cout << "Input m, n:";
cin >> m >> n;
int a[N][N], at[M][M];
InputMatrix(a, m, n);
Transpose(a, at, m, n);
PrintMatrix(at, n, m);
return 0;
}
void InputMatrix(int a[][N], int m, int n)
{
cout << "Input " << m << "*" << n << " matrix:" << endl;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
}
void Transpose(int a[][N], int at[][M], int m, int n)
{
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
at[j][i] = a[i][j];
}
void PrintMatrix(int at[][M], int n, int m)
{
cout << "The transposed matrix is:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << at[i][j] << "\t";
cout << endl;
}
}
```
希望能帮到你!
阅读全文