杭电1089(我为自己代言)
Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
Sample Output
6 30
问题描述
你的任务是计算a + b。
你必须有发现一些问题有相同的标题,是的,所有这些问题都为同一个目标而设计的。
输入
输入将包含一系列对整数a和b,之间用一个空格来分隔,每行一对整数。
输出
对于每一对输入整数a和b,你应该输出的总和a和b在一行,和一行输出输入的每一行。
样例输入
1 5
10 20
样例输出
6
30
#include<stdio.h>
int main()
{
int a,b,sum;
while(scanf("%d %d",&a,&b)!=EOF)
{
sum=a+b;
printf("%d\n",sum);
}
return 0;
}
开始少了个换行符(\n)显示 表示错误 纠结了半天。。。
附上!=EOF的解释吧 我也不懂百度到了感觉差不多的解释
要说!=EOF,首先要知道scanf的返回值。
一开始学C语言,大家知道scanf是用于输入的,通常单独写成一句:
scanf (...) ;
殊不知,scanf也是有返回值的,其返回值表示正常输入的参数个数
如果scanf输入的时候碰到了输入的末尾,就会返回EOF。
EOF是End of file(文件末尾)的意思,其值为-1。
while (scanf (...) != EOF) 就是说,在输入没有达到文件末尾的时候执行循环。
(输入将包含一系列对整数a和b,之间用一个空格来分隔,每行一对整数。需要用!=EOF)
其实我也不怎么懂