题目:
Your task is to calculate the sum of some integers.
Input
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.
Output
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.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
题意:
给你一个数字n,代表后面跟着n个数字,然后让你求出来n个数字的和;
代码如下:
C++:
#include<stdio.h>
int main()
{
int n,m,s;
while(~scanf("%d",&n))
{
s=0;
for(int i=0;i<n;i++)
{
scanf("%d",&m);
s+=m;
}
printf("%d\n",s);
}
return 0;
}
JAVA:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int m,a,s;
while(input.hasNext()) {
m=input.nextInt();
s=0;
for(int i=0;i<m;i++) {
a=input.nextInt();
s=s+a;
}
System.out.println(s);
}
}
}