1 #include<stdio.h> 2 #include<math.h> 3 #define N 5 4 int n; 5 int a[N][N]; 6 void show(){ 7 int i, j; 8 for(i=0; i<n; i++){ 9 for(j=0; j<n; j++){ 10 printf("%3d", a[i][j]); 11 } 12 printf(" "); 13 } 14 } 15 16 void reverse(){ 17 int i, j; 18 for(i=0; i<n; i++){ 19 for(j=i+1; j<n; j++){ 20 int t=a[i][j]; 21 a[i][j]=a[j][i]; 22 a[j][i]=t; 23 } 24 } 25 } 26 int main(){ 27 //生成原始矩阵 28 29 int i, j; 30 scanf("%d", &n); 31 for(i=0; i<n; i++){ 32 for(j=0; j<n; j++){ 33 a[i][j]= i * n + j + 1; 34 } 35 } 36 printf("The original matrix is: "); 37 show(); 38 printf("The changed matrix is: "); 39 reverse(); 40 show(); 41 42 }