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
解题过程
#include <stdio.h>
int main()
{
int n,num,x,i,y;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&y);
num=0;
while(y--)
{
scanf("%d",&x);
num+=x;
}
printf("%d\n",num);
}
return 0;
}
解题总结
对题进行理解,利用循环进行解答就可以了。
心得感受
可以试着用简单的函数进行一系列的操作。也许会有新的发现。