C/C++编程学习 - 第3周 ① 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,计算a与b的和,并输出。

听起来也没那么难~ 主要注意一下多组输入。

C语言代码:

#include<stdio.h>
int main()
{
    
    
    int a , b;
    while(scanf("%d %d",&a, &b) != EOF)	//成功AC的关键
        printf("%d\n",a + b);
    return 0;
}

C++代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int a, b;
	while(cin >> a >> b)
		cout << a + b << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44826711/article/details/112859722