A+B for Input-Output Practice (IV)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 120096 Accepted Submission(s): 63428
Problem Description
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
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n, x;
while(scanf("%d",&n)!=EOF)
{
int sum = 0;
if(n==0)
{
break;
}
else
{
for(int i=0; i<n; i++)
{
scanf("%d",&x);
sum = sum + x;
}
printf("%d\n",sum);
}
}
return 0;
}
本文介绍了一个经典的编程练习题“A+B for Input-Output Practice (IV)”,该题目要求计算一组整数的总和。文章提供了完整的C++代码实现,并详细解释了如何通过输入多个整数并计算它们的总和。
565

被折叠的 条评论
为什么被折叠?



