#include <stdio.h>
int main()
{
int array[1][1];
for (int x = 0; x < 2;x++)
{
printf("x%d\n",x);
for (int y = 0; y < 2;y++)
{
printf("y%d\n",y);
scanf("%d\n",&array[x][y]);
}
}
return 0;
}
我正在尝试扫描数组元素以启动矩阵计算器。该代码需要 5 个数字作为输入,而不是 4 个。在 x0 和 y0 之后,它需要两个数字,不知道为什么。我发布了输出。
x0
y0
1
1
y1
1
x1
y0
1
y1
1
最佳答案
这是一个工作版本:
#include <stdio.h>
int main()
{
// Define a 2x2 array
int array[2][2];
for (int x = 0; x < 2;x++)
{
printf("x%d\n",x);
for (int y = 0; y < 2;y++)
{
printf("y%d\n",y);
scanf("%d", &array[x][y]);
}
}
return 0;
}
其中 array[n]
的索引为 0
..n-1
,其中 if n=1
您只有一个有效索引。
关于c - 阵列扫描两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52156152/