1. 程式人生 > >A + B Problem HDU - 1000(語法練習題)

A + B Problem HDU - 1000(語法練習題)

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

題目分析:
本題的重點是能多次輸入資料實現運算,並不是輸入一次,運算一次就退出程式了。
程式說明:
把cin>>a>>b當成while函式的引數就可以實現要求了,因為cin遇到輸入終止的時候會返回一個0,而while遇到0時就會退出迴圈。
程式實現:

#include <iostream>
using namespace std;
int main()
{
 int a, b;
 while (cin >> a >> b)
 {
  cout << a + b << endl;
 }
}