Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在一个代码中检测错误时遇到困难,该代码在输入时得到10个数字,在输出时给出它们的和。_C_Codeblocks - Fatal编程技术网

C 在一个代码中检测错误时遇到困难,该代码在输入时得到10个数字,在输出时给出它们的和。

C 在一个代码中检测错误时遇到困难,该代码在输入时得到10个数字,在输出时给出它们的和。,c,codeblocks,C,Codeblocks,我试图编写一个代码,在输入端接收10个数字,并在输出端给出它们的总和,出于某种原因,代码每10个数字就工作一次,但是当我将数字1作为第一个输入,将数字2作为第二个输入时,它就不工作了。它给了我以下信息: 代码如下: #include <stdio.h> int main() { int i, sum = 0, value, numbers_to_read; printf("Please enter number of values\n"); scanf("%d", &num

我试图编写一个代码,在输入端接收10个数字,并在输出端给出它们的总和,出于某种原因,代码每10个数字就工作一次,但是当我将数字1作为第一个输入,将数字2作为第二个输入时,它就不工作了。它给了我以下信息:

代码如下:

#include <stdio.h>
int main()
{
int i, sum = 0, value, numbers_to_read;
printf("Please enter number of values\n");
scanf("%d", &numbers_to_read);
for( i = 0; i < numbers_to_read; i++ ) {
printf("Enter the next integer: ");
scanf("%d", &value);
sum = sum + value;
}
printf("The sum of the %d numbers is %d\n",
numbers_to_read, sum);
return 0;
}
#包括
int main()
{
int i,sum=0,值,读取的数字;
printf(“请输入数值\n”);
scanf(“%d”,读取的数字(&U);
对于(i=0;i
“当我将数字1作为第一个输入,将数字2作为第二个输入时,它不起作用”

scanf(“%d”,&numbers\u to\u read)//输入为1
对于(i=0;i

因此,输出确实是2。

向下投票的目的是什么?我不理解这个问题。我编译并运行了您的程序,告诉它1个数字,然后输入数字是2,一系列数字的总和是2。就像您的屏幕图像一样,希望我从控制台运行它,但没有得到继续的提示。@FirasAliAbdelGhani您看到图片了吗?它会问你想输入多少数字,你说“1”。。它似乎完全按照您的意愿运行。@FirasAliAbdelGhani您的程序完全按照您的意愿运行。如果你期望不同的输出,请编辑你的帖子并说出来,包括细节。
scanf("%d", &numbers_to_read); //input is 1
for( i = 0; i < numbers_to_read; i++ ) { // loop runs 1 time
printf("Enter the next integer: "); 
scanf("%d", &value); //value entered is 2
sum = sum + value; //sum = 0 +2
}