c++编程:多组数据求和
c++编程:多组数据求和
不断读取两个整数,计算它们的和,并立即输出结果,直到用户主动结束输入。
输入:
1 2
3 4
5 6
输出:
3
7
11
#include<bits/stdc++.h> using namespace std; int main(){ int a, b; while(cin >> a >> b) { // ✅ 连续读取两个数 cout << a + b << endl; } return 0; }不断读取两个整数,计算它们的和,并立即输出结果,直到用户主动结束输入。
输入:
1 2
3 4
5 6
输出:
3
7
11
#include<bits/stdc++.h> using namespace std; int main(){ int a, b; while(cin >> a >> b) { // ✅ 连续读取两个数 cout << a + b << endl; } return 0; }