我想创建一个二维数组,其中行数和列数是固定的,列值将从控制台输入中获取。
void main() {
int myArray[3][5];
int i;
int a, b, c, d, e; // for taking column values
for (i = 0; i < 3; i++) { // i represents number of rows in myArray
printf("Enter five integer values: ");
// taking 5 integer values from console input
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
// putting values in myArray
myArray[i][1] = a;
myArray[i][2] = b;
myArray[i][3] = c;
myArray[i][4] = d;
myArray[i][5] = e;
}
// print array myArray values (this doesn't show the correct output)
for (i = 0; i < 3; i++) {
printf("%d\t %d\t %d\t %d\t %d\t", &myArray[i][1], &myArray[i][2],
&myArray[i][3], &myArray[i][4], &myArray[i][5]);
printf("\n");
}
}
当我运行这个程序时,它正确地接受输入,但没有按预期显示数组输出。我怎么能这样做,有什么想法吗?请帮忙。