A+B for Input-Output Practice (VI)
Problem Description
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
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
10
15
code:
#include<iostream>
using namespace std;
int main()
{
int n,x,sum;
while(cin>>n)
{
sum=0;
while(n--)
{
cin>>x;
sum+=x;
}
cout<<sum<<endl;
}
return 0;
}
本文介绍了一道经典的A+B问题,通过输入多个整数并计算其总和来实践输入输出操作。提供了完整的C++代码实现,适用于初学者理解和掌握基本的编程技巧。
356

被折叠的 条评论
为什么被折叠?



