#include <stdio.h>
int main() {
int num_r, num_c;
scanf("%d %d", &num_r, &num_c);
//將值寫入
int matrix[num_r][num_c];
for (int i = 0; i < num_r; i++) {
for (int j = 0; j < num_c; j++) {
scanf("%d", &matrix[i][j]);
}
}
//對調行與列
int change = num_r;
num_r = num_c;
num_c = change;
//印出結果
for (int i = 0; i < num_r; i++) {
for (int j= 0; j < num_c; j++) {
if (i != j) { //若行與列不同,要對調印出
printf("%d ", matrix[j][i]);
} else { //若行與列相同則直接印出
printf("%d ", matrix[i][j]);
}
}
if ((i + 1) != num_r) { //若不適最後一列則要換行
printf("\n");
}
}
return 0;
}
想請問一下少考慮了哪個地方,一直過不了測資
#include
int main() {
int num_r, num_c;
scanf("%d %d", &num_r, &num_c);
//將值寫入
int matrix[num_r][num_c];
for (int i = 0; i < num_r; i++) {
for (int j = 0; j < num_c; j++) {
scanf("%d", &matrix[i][j]);
}
}
//對調行與列
int change = num_r;
num_r = num_c;
num_c = change;
//印出結果
for (int i = 0; i < num_r; i++) {
for (int j= 0; j < num_c; j++) {
if (i != j) { //若行與列不同,要對調印出
printf("%d ", matrix[j][i]);
} else { //若行與列相同則直接印出
printf("%d ", matrix[i][j]);
}
}
if ((i + 1) != num_r) { //若不適最後一列則要換行
printf("\n");
}
}
return 0;
}想請問一下少考慮了哪個地方,一直過不了測資
輸入有多筆測資