C语言的简易编程问题Your task is to Calculate the sum of some integers

学习 时间:2026-04-02 20:24:51 阅读:2437
C语言的简易编程问题Your task is to Calculate the sum of some integers.InputInput contains multiple test cases.Each test case contains a integer N,and then N integers follow in the same line.A test case starting with 0 terminates the input and this test case is not to be processed.OutputFor each group of input integers you should output their sum in one line,and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 50 Sample Output1015Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015

最佳回答

痴情的寒风

开朗的猫咪

2026-04-02 20:24:51

#include <stdio。h>

int main()
{
bool newlineok=false;
int n,a,ans,i;
while(true)
{
scanf("%d",&n);
if(n==0) return 0;

if(!newlineok) newlineok=true;
else printf("\n");

ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&a);
ans+=a;
}
printf("%d",ans);
}
return 0;
}
再问: 我要的是最基础的那种,你这是什么啊?
再答: 您确定您要我写C?不是C++? 提示: cout是标准C++的。 printf常常用于标准C的。 --------------------------------------------- 请问您需要多基础? 请问我可以使用if、for、while当中的哪些?
再问: newlineok,ans都是见都没见过,我要标准C的,简单的,if、for、while都可以啊,但是你在括号中间加的单词我实在是不理解什么意思
再答: 亲,newlinkok和ans是我定义的…… 另外bool是布尔变量(表示真和假的变量)

最新回答共有2条回答

  • 留胡子的导师
    回复
    2026-04-02 20:24:51

    #include <stdio。h>int main(){bool newlineok=false;int n,a,ans,i;while(true){scanf("%d",&n);if(n==0) return 0;if(!newlineok) newlineok=true;else printf("\n");ans=0;for(i=0;i<n;i++){scanf("%d",&a);ans+=a;}printf("%d",ans);}return 0;} 再问: 我要的是最基础的那种,你这是什么啊? 再答: 您确定您要我写C?不是C++? 提示: cout是标准C++的。 printf常常用于标准C的。 --------------------------------------------- 请问您需要多基础? 请问我可以使用if、for、while当中的哪些?再问: newlineok,ans都是见都没见过,我要标准C的,简单的,if、for、while都可以啊,但是你在括号中间加的单词我实在是不理解什么意思 再答: 亲,newlinkok和ans是我定义的…… 另外bool是布尔变量(表示真和假的变量)

上一篇 剪叉式液压升降平液压升降机哪家最好?

下一篇 装修公司的排名哪些公司