码迷,mamicode.com
首页 > 其他好文 > 详细

A+B 5

时间:2020-01-31 10:47:21      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:a+b   计算   ace   for   包含   个数   int   cout   names   

你的任务是计算一些整数的和Input输入包含多组样例。
每组样例包含一个整数N,然后在同行有N个整数。
若N = 0,则表示输入结束,这个样例不需要被处理。Output对于每组用例,你应当输出这组样例N个数字的和,每个输出占一行。Sample Input

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

Sample Output

10
15


#include<iostream>
using namespace std;
int main(void) {
int a,i,c=0;
int b[100];
while(cin>>a) {
if(a==0) {
break;
} else
for(i=0; i<a; i++) {
cin>>b[i];
}
for(i=0; i<a; i++) {
c+=b[i];

}
cout<<c<<endl;
c=0;
}
}

 

在前几道的基础上加入一些循环与判断就行了。

A+B 5

标签:a+b   计算   ace   for   包含   个数   int   cout   names   

原文地址:https://www.cnblogs.com/heroin1/p/12244641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!