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.
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.
It is guarantied that all integers and the sum are in the range of 32-int.
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
一,正确方法
#include <stdio.h>
int main(void)
{
int a, b;
while (scanf("%d%d", &a, &b) != EOF)
{
printf("%d\n", a + b);
}
return 0;
}
二,原理
while循环为什么永远都出不来?因为while里面有一个scanf(),每次运行到while都会等待你输入回车,然后scanf()读取你输入的数字,如果你输入的数字小于两个的时候输入回车,scanf()会继续等待你输入的数字大于等于两个然后执行while()循环。