1.格式一:
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
#include<stdio.h>
int main(void) {
int n;
int num;
int sum;
while(scanf("%d",&n) == 1 &&n!=0) {
sum = 0;
while(n--) {
scanf("%d",&num);
sum += num;
}
printf("%d\n",sum);
}
return 0;
}
格式二:
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10
15
6
#include<stdio.h>
int main(void) {
int n;
int num;
int sum;
int case1;
scanf("%d",&case1);
while(case1) {
sum = 0;
scanf("%d",&n);
while(n--) {
scanf("%d",&num);
sum += num;
}
if(case1!=1)
printf("%d\n\n",sum);
else
printf("%d\n",sum);
case1--;
}
return 0;
}