c++3x3矩阵转置函数
时间: 2023-12-17 12:02:50 浏览: 59
以下是一个C++实现3x3矩阵转置的函数示例:
```c++
#include <iostream>
using namespace std;
void transpose(int arr[3][3]) {
for(int i=0; i<3; i++) {
for(int j=i+1; j<3; j++) {
int temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
}
}
int main() {
int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
cout << "Original Matrix:" << endl;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
transpose(arr);
cout << "Transposed Matrix:" << endl;
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
```