[HDU1000] A + B Problem

Problem Description

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,求A+B。

但是是多行的,因此需要用循环反复读取。

又因为输入数据中没有说有多少行,因此不能使用计数循环,而要通过while循环判断是否到达文件尾,如果是则停止循环。

而在循环中则是将输入的两个数的和算出,并输出。

因此C/C++代码如下:

C

#include <stdio.h>
int main()
{
    int a, b;
    while (scanf("%d%d", &a, &b) != EOF)
        printf("%d
", a + b);
    return 0;
}

C++

C++和C区别不大,仅仅是<stdio.h>和<iostream>,printf和cout,scanf和cin,以及如何判断EOF。

#include <iostream>
int main()
{
    int a, b;
    while (cin >> a >> b)
        cout << (a + b) << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/collectionne/p/6786367.html