Only those who are filled with sunshine in their hearts will not despair, so even if the environment is very poor, our hearts still depend.
Description
Write a function to transpose a given two-dimensional array (3x3), that is, a row and column interchange.
Input
A 3x3 matrix.
Output
The Matrix after the transpose
Sample Input
1 2 3
4 5 6
7 8 9
Sample Output
1 4 7
2 5 8
3 6 9
HINT
The main function is given as follows, and the following main functions are not required for submission
/* C code * *
int main ()
{
int a[3][3];
int i,j;
for (i=0; i<3; i++)
For (j=0 j<3; j + +)
scanf ("%d", &a[i][j]);
Zhuangzhi (a);
for (i=0; i<3; i++)
{
For (j=0 j<3; j + +)
printf ("%d", a[i][j]);
printf ("\ n");
}
return 0;
}
/* C + + code * *
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;
}
#include <stdio.h> void Zhuangzhi (int a1[3][3]) {int i,j,t;
For (i=0, i<3; i++) for (j=i; j<3; j + +)//double loops to reverse the array {t=a1[j][i];
A1[J][I]=A1[I][J];
a1[i][j]=t;
int main () {int a[3][3];
int i,j;
For (i=0 i<3; i++) for (j=0; j<3; j + +) scanf ("%d", &a[i][j]);
Zhuangzhi (a);
For (i=0 i<3; i++) {for (j=0; j<3; j + +) printf ("%d", a[i][j]);
printf ("\ n");
return 0; }