該部分的代碼,如果你想編譯它,下面。爲什麼我的C程序要求輸入超過它的值?而額外的輸入甚至不做任何事
基本上我不得不採取以下數據並將其輸入到程序:
4 5
12 5 7 0 -3
9 11 2 5 4
0 -5 9 6 1
2 12 93 -15 0
5 3
7 1 31
0 0 5
-5 -3 2
9 41 11
0 13 31
第一4 5 & 5 3表示第一和第二矩陣的維數,而數據後它是數據爲矩陣。
問題是,當我複製並粘貼它後,它要求再輸入一次,並且當我輸入任何東西(比如說84)時它能夠完美地工作(輸出明智),並且84看起來什麼都不做。爲什麼它要求額外的一個?
#include <stdio.h>
int main(int argc, char *argv[]) {
int rows1 = 1, columns1 = 1, rows2 = 1, columns2 = 1; // variables for number of rows and columns in each matrix
int i, j, k; // loop variables
// These will affect the loop's length
scanf("%d %d", &rows1, &columns1);
int matrix1[rows1][columns1];
for (i = 0; i < rows1; i++) {
for (j = 0; j < columns1; j++) {
scanf("%d ", &matrix1[i][j]);
}
}
scanf("%d %d", &rows2, &columns2);
int matrix2[rows2][columns2];
for (i = 0; i < rows2; i++) {
for (j = 0; j < columns2; j++) {
scanf("%d ", &matrix2[i][j]);
}
}
}
你的數據不是clear.Can你細說嗎? – Teja 2012-03-01 16:31:19
對不起,它在實際文章中格式不佳。我現在修好了。 – 2012-03-01 16:42:10