您的位置:首页 > 编程语言 > PHP开发

ACM---1089: A+B for Input-Output Practice (V)

2014-11-16 06:37 344 查看
题目描述
Your task is to calculate the sum of some integers.

输入
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

输出
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.

样例输入
2
4 1 2 3 4
5 1 2 3 4 5

样例输出
10
15
代码如下:
#include<stdio.h>

int main(void)

{

int n, m, a, sum, i, j;

while(scanf("%d", &n) != EOF)

{

for(i = 0; i < n; i ++)

{

scanf("%d", &m);

sum = 0;

for(j = 0; j < m; j ++)

{

scanf("%d", &a);

sum = sum + a;

}

printf("%d\n", sum);

}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: