Title Description
Write a function that enables a given two-dimensional array (3x3) transpose, that is, the row and column interchange.
Input
A 3x3 matrix
Output
The Matrix after transpose
Sample input
1 2 34 5 67 8 9
Sample output
Answer
#include <iostream>using namespace std;void zhuangzhi (int c[3][3]) { int b[3][3],i,j; for (i=0;i<3;i++) for (j=0;j<3;j++) b[j][i]=c[i][j]; for (i=0;i<3;i++) for (j=0;j<3;j++) c[i][j]=b[i][j];} int main () { int a[3][3]; int i,j; for (i=0; i<3; i++) for (j=0; j<3; j + +) cin>>a[i][j]; Zhuangzhi (a); For (i=0, i<3; i++) {for (j=0; j<3; j + +) cout<<a[i][j]<< ""; cout<<endl; } return 0;}
Gradually found that they forget some of the contents of the last semester, at the beginning only to think that the change of formal parameters will not affect the actual parameters, so in the formal parameters there are various pointers, references, and finally to take the address, all error. There are many ways to know that the two-dimensional function itself is a pointer, the change of the parameters can change the actual parameters, although do not know why c=b did not change .... Just give yourself a warning, remember that there is time to review the previous content
Some projects--permutation of two-dimensional arrays