我想在我的 distCasas
数组中添加数字 (nums
),但 idx
递增错误。我在索引中保留 nums
0, 2, 4, ...
不是
0, 1, 2, ...
代码:
int numCasas, idx, distCasas[10], nums;
scanf("%d", &numCasas);
for (idx = 0; idx < numCasas; idx++)
{
scanf("%d", &nums);
distCasas[idx] = nums;
idx++;
}
最佳答案
您将 idx 递增两次。删除第二个 idx++,以便您的代码如下所示。
scanf("%d", &numCasas);
for (idx = 0; idx < numCasas; idx++)
{
scanf("%d", &nums);
distCasas[idx] = nums;
}
关于c - 变量没有正确递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23273945/