A+B Problem
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
问题简述:
第一行输入两个整型数字并以空格分开,第二行输出A+B的结果,并且要可以输入多组数据。
问题分析:
为了实现可以输入多组数据即程序不能结束,考虑利用while搭配 EOF 使用。
Virtual Judge通过的代码如下:
#include <iostream>
using namespace std;
int main()
{
int a, b;
while (scanf_s("%d %d", &a, &b) != EOF)//能够让while 下面的语句一直执行不会让程序结束
{
printf("%d\n", a + b);
}
return 0;
}