做一个加法运算器,算出N组加数的和。(0 <= N <= 10)
输入
N+1行,每行两个整数,以0 0 结束。
输出
N行,每行一个整数,即算出的和。
样例
输入 复制
3 5
8 1
3 8
0 0
输出 复制
8
`
`````c++
9
11
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a=1,b=1;
while(cin>>a>>b)
{
if(a!=0&&b!=0)
{
cout<<a+b<<endl;
}
else
{
break;
}
}
}
```c++
```c++
```c++
哪里错了?
代码本身没错,但不符合题意啊。你这样是输入两个数字,马上输出结果,不是输入一组数字,然后输出一组结果啊
#include
using namespace std;
int main()
{
int a=0,b=0,res[100], i=0, t=0;
cin>>a>>b;
while(a!=0 || b!=0)
{
res[t++] = a+b;
cin>>a>>b;
}
while(i<t)
cout<<res[i++]<<endl;
return 0;
}