C语言的简易编程问题Your task is to Calculate the sum of some integers
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
最佳回答
#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是布尔变量(表示真和假的变量)
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是布尔变量(表示真和假的变量)
热门文章
- 康达学院专转本五年制
- 高考一个考场分ab卷吗
- not only but also用法
- 某物体做自由落体运动,从释放开始计时,则物体在前2s内的平均速度为______m/s,物体下落2m时的速度大小为______m/s.
- 三角函数公式大全表格
- 地理中考必背知识点2022
- 2013-2014学年小学六年级科学上学期期末考试试卷及答案
- 人教版2014-2015学年小学五年级英语第二学期期中教学质量检测试卷及答案
- 【Linux驱动开发】设备树详解(二)设备树语法详解
- 别跟客户扯细节
- 在别的城市买房子能落户吗
- 卖房前要把装修贷还完吗
- 高中政治教学提高教学效果的方法探究
- “互联网+”背景下的初中英语课堂教学改革与创新策略研究
- 2022年终止合同范本
- 租房合同范本范文
- 如何挑选土豆
- 如何挑选土鸡
