problem:hdoj 1000
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.
Sample Input:1 1
Sample Output:2
#include <stdio.h>
int main()
{
int A,B;
while(scanf("%d%d",&A,&B)!=EOF) //wrong了两次,其实是没有到文件末尾
{
printf("%d\n",A+B);
}
return 0;
}
VC6运行效果图
参考资料1 http://www.douban.com/note/220299804/
1. scanf 函数是有返回值的,它的返回值可以分成三种情况
1) 正整数,表示正确输入参数的个数。例如执行 scanf("%d %d", &a, &b);
如果用户输入"3 4",可以正确输入,返回2(正确输入了两个变量);
如果用户输入"3,4",可以正确输入a,无法输入b,返回1(正确输入了一个变量)。
2) 0,表示用户的输入不匹配,无法正确输入任何值。如上例,用户如果输入",3 4",返回0。
3) EOF,这是在stdio.h里面定义的常量(通常值为-1),表示输入流已