C++刷题七——加法运算集锦(2)

(一)

Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output

For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
 
#include <iostream>
using namespace std;
int main()
{
    int n,N;
    cin>>N;
    while(N>0)
    {
        int  i=1,s=0,a;
        cin>>n;
        for(; i<=n; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;
        N--;
    }
    return 0;
}


(二)

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.

 

 

/* All rights reserved.
 * 文件名称:test.cpp
 * 作者:陈丹妮
 * 完成日期:2015年 4 月 21 日
 * 版 本 号:v1.0
 */
#include <iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int  i=1,s=0,a;
        for(; i<=n; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl;
    }
    return 0;
}


(三)

Description

Your task is to Calculate a + b.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        cout<<n+m<<endl<<endl;;
    }
    return 0;
}

(四)

Description

Your task is to calculate the sum of some integers

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line

Output

For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
#include <iostream>
using namespace std;
int main()
{
    int n,N;
    cin>>N;
    while(N>0)
    {
        int  i=1,s=0,a;
        cin>>n;
        for(; i<=n; i++)
        {
            cin>>a;
            s+=a;
        }
        cout<<s<<endl<<endl;
        N--;
    }
    return 0;
}

 
 
心得体会:看清题目所要求的条件,按要求输出。这就要求我们,即使再简单的题目,也要细心,细心,再细心!
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值