两个for循环嵌套的表达式1的省略
#include<stdio.h>int main() {
int i=0, j=0;
int temp=0;
//temp= 0;
//i = 0; j = 0;
int a[3][3] = { 1,2,3,4,5,6,7,8,9 };
printf("初始:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d", a[i][j]);
}
printf("\n");
}
/*******************************************************/
printf("转置方法1:\n");
for (i=0; i < 3; i++) {
for (j=i; j < 3; j++) {
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", a[i][j]);
}
printf("\n");
}
/*******************************************************/
printf("转置方法2:\n");
for (; i < 3; i++) {
for (; j < 3; j++) {
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d ", a[i][j]);
}
printf("\n");
}
getchar();
getchar();
getchar();
return 0;
}
当把转置2放在转置1后面就可以正常转置,放在1前面就无法转置这是为什么