A+B problem(4) 南邮ACM的OJ

本文介绍了一个简单的A+B Problem求和程序实现方法。该程序能够接收多组测试数据,每组测试数据由一个整数N及随后的N个整数组成,并计算这些整数的总和。程序通过循环读取输入并输出每组测试数据的求和结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/***********************************************
A + B Problem (4)
描述

Calculate the sum of some integers.

输入

The input will consist of multiple test cases. Each test case consist of an integer N and then N integers following in the same line,separated by a space. A line starting with 0 terminates the input and this line is not to be processed.

输出

For test case, you should output their sum in one line, and with one line of output for each line in input. After each test case output, you should output one blank line.

样例输入

4 1 2 3 4
5 1 2 3 4 5
0

样例输出

10

15

************************************************************/

#include <iostream>
//#include <fstream>
using namespace std;
int main()
{
// ifstream cin("1.txt");
 int n,i,sum=0;
 int temp;
 cin>>n;
 while(n!=0)
 {
  for(i=0;i<n;i++)
  {
   cin>>temp;
   sum+=temp;
  }
  cout<<sum<<"/n"<<endl;
  sum=0;
  cin>>n;
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值