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
题意:每组数据线输入一个整数,表示本组数据包含整数的个数,输出这几个整数的和,当数据第一个数是0时,程序结束。
分析:现在while语句的判断条件里面判断每组输入数据的第一个数据是不是为0,然后在while语句里面用for循环语句输入后面的各个整数。
AC源代码(C语言):
1 #include<stdio.h> 2 int main() 3 { 4 int a,b,s,i; 5 while(scanf("%d",&a)&&a) 6 { 7 s=0; 8 for(i=1;i<=a;i++) 9 { 10 scanf("%d",&b); 11 s+=b; 12 } 13 printf("%d\n",s); 14 } 15 return 0; 16 }
2013-01-29