题目描述
Your task is to calculate the sum of some integers.
输入
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
输出
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
贴士
使用while(scanf("%d", &N))会导致输出超限,应该使用while(scanf("%d", &N) != EOF )
代码
#include<stdio.h>
int main()
{
int N, num, i, sum;
while(scanf("%d", &N) != EOF)
{
sum = 0;
for(i = 0; i < N; i++)
{
scanf("%d", &num);
sum += num;
}
printf("%d\n", sum);
}
return 0;
}