思路:第一列与第一行换位,第二列与第二刚换。如此反复。
- #include <stdio.h>
#define M 5
#define N 5
int main(){
int m,j,k,i; int temp;
int (*p1)[5];
int a[M][N] = {{1,2,3,4,5}, {5,9,6,3,4}, {8,9,5,6,4}, {7,8,5,1,6}};
p1 = a;
for( m = j = 0; m < 5; ++m, ++j)
for(i = k = 0; i < 5; ++i, ++k){
temp = ((p1 + k) + j);
((p1 + k) + j) = ((p1 + m) + i);
((p1 + m) + i) = temp;temp过渡
}
for( m = j = 0; m < 5; ++m, ++j){
for(i = k = 0; i < 5; ++i, ++k)
printf("%d\t", ((p1 + j) + k));
printf("\n"); 输出矩阵
}
return 0;
}