#956. A+B Problem
A+B Problem
说明
输入两个自然数a,b,输出他们的和。输入格式
共一行:两个自然数a和b,中间用一个空格隔开。
(0<=a,b<=32767)
输出格式
共一行:输出a+b。123 500
623
提示
你的程序应该从标准输入stdin('Standard Input')获取输出 并将结果输出到标准输出stdout('Standard Output')。
例如,在C语言可以使用'scanf',在C++可以使用'cin'进行输入;在C使用'printf',在C++使用'cout'进行输出。
用户程序不允许直接读写文件,如果这样做可能会判为运行时错误"Runtime Error"。
下面是题号为1000的题目的参考答案:
C++:
#include <iostream>
using namespace std;
int main() {
int a,b;
while (cin >> a >> b) {
cout << a+b << endl;
}
return 0;
}
C:
#include <stdio.h>
int main() {
int a,b;
while (scanf("%d %d",&a, &b) != EOF) {
printf("%d\n",a+b);
}
return 0;
}
PASCAL:
program p1001(Input,Output);
var
a,b:Integer;
begin
while not eof(Input) do
begin
Readln(a,b);
Writeln(a+b);
end;
end.
Java:
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int a, b;
while (cin.hasNext()) {
a = cin.nextInt();
b = cin.nextInt();
System.out.println(a + b);
}
}
}