1 //takePlace里的循环写错了,j循环应该是
2 //for (j=i;j<3;j++)
3 //你那个写的交换了2遍,又变回原来的了。*//
4
5 #include <stdio.h>
6
7 int Array[3][3];
8 void takePlace( )
9 {
10 int i,j,t;
11 for(i=0;i<3;i++)
12 for(j=i;j<3;j++)
13 {
14 t=Array[i][j];
15 Array[i][j]=Array[j][i];
16 Array[j][i]=t;
17 }
18 }
19
20 int main()
21 {
22 int i,j;
23 int n=0;
24 printf("please enter 9 numbers:\n");
25 for(i=0;i<3;i++)
26 for(j=0;j<3;j++)
27 {
28 scanf("%d",&Array[i][j]);
29 printf("%3d",Array[i][j]);
30 n+=1;
31 if(n%3==0)
32 printf("\n");
33 }
34 printf("Now,开始转置.......\n");
35 takePlace( );
36 n=0;
37 printf("转置后的结果为:\n");
38 for(i=0;i<3;i++)
39 for(j=0;j<3;j++)
40 {
41 printf("%3d",Array[i][j]);
42 n+=1;
43 if(n%3==0)
44 printf("\n");
45 }
46 }
你要保守你心,胜过保守一切。
作者:刘俊涛的博客