杭州电子科技大学 online judge 1000 题 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.

大致意思就是:不断输入A和B,输出它们的和。

思路

首先,题目要求不断输入A和B,但没有给出组数!!!!

所以最好是用while函数判断是否输完,代码块如下:

while ( scanf("%d %d", &A, &B) != EOF ) {
    ………………
}

说明:scanf函数在输入成功时会返回输入变量的个数,如果输入失败就会返回EOF,千万不要写“!= 0”!!!别问我是怎么知道的 

接下来就简单了,不再一一赘述。

代码(C++) 

#include     //万能头,不用多说。

using namespace std;

int A, B;    //定义变量

int main() {
    while( scanf("%d %d", &A, &B ) != EOF )
    {
        printf("%d\n", A + B );    //也可以int C = A + B;    printf("%d", C);
    }
    
    return 0;    //完美结束
}

    你可能感兴趣的:(杭电OJ,c++)