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

A+B for Input-Output Practice (V)

2020-03-30 07:34 1036 查看

Problem Description
Your task is to calculate the sum of some integers.
Input
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.
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
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15

C

#include <stdio.h>
#pragma warning(disable:4996)
int main(void)
{
int N,M,digit,i,sum;
scanf("%d",&N);
while(N--)
{
scanf("%d",&M);
for(sum=0,i=0;i<M;i++)
{
scanf("%d",&digit);
sum+=digit;
}
printf("%d\n",sum);
}
return 0;
}

没什么要说的,注意sum的值归0.

  • 点赞
  • 收藏
  • 分享
  • 文章举报
coffee__a 发布了28 篇原创文章 · 获赞 4 · 访问量 1777 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: