1. 程式人生 > >問題 1090: A+B for Input-Output Practice (VI)

問題 1090: A+B for Input-Output Practice (VI)

 

輸入 Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line. 輸出 For each test case you should output the sum of N integers in one line, and with one line of output for each line in input. 樣例輸入
4 1 2 3 4
5 1 2 3 4 5

ACM大賽   大家一起探討

 

#include<stdio.h>
int main()
{
int N;
int sum;
int temp;
while(scanf("%d",&N)==1)
{

//注意讓sum初始化為0 
sum=0;
while(N--){
scanf("%d",&temp);
sum+=temp;
}
printf("%d\n",sum);
}
return 0;
}