C语言的简易编程问题Your task is to Calculate the sum of some integers
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/19 10:24:52
C语言的简易编程问题
Your task is to Calculate the sum of some integers.
Input
Input 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.
Output
For 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 Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
Your task is to Calculate the sum of some integers.
Input
Input 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.
Output
For 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 Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
#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是布尔变量(表示真和假的变量)
C语言的简易编程问题Your task is to Calculate the sum of some integers
Your task is to Calculate a + b.
英语翻译Your task is to find the sum of all integer numbers lyin
find the largest of three consecutive integers whose sum is
解一道有英语的奥数题:The sum of n different positive integers is less
Given an integer N(0 ≤ N ≤ 1000),your task is to calculate
杭电ACM1092题目 Problem Description Your task is to Calculate th
Java write a program to calculate the sum of each of the ser
c语言编程sum problem
What is the greatest of 5 consecutive integers if the sum of
acm Calculate the Sum
:the sum of 14 consecutive integers is 217,what is the sixth