#include<stdio.h>
int main(){
int a,b;
while(scanf("%d%d",&a,&b) != EOF){
printf("%d\n", a+b);
}
return 0;
}
对于上述程序,有几个问题不懂:
1 main 函数前可否改成void类型
2 EOF是文件结束的意思,但和a,b有何关系?这里为啥要用它,不能直接舒服a,b的值吗?是不是和题目又关,题目是这样的:The input consists of N lines, each of which contains two integers A and B, separated by a space.
For each pair of A and B, you should first calculate the sum of A and B and then print the result to the stdout on a single line.
那能不能去掉EOF,而直接写scanf呢?还有那两句英语是什么意思呢,有没有特定要求呢
1、mian()是函数,是从操作系统调用的。既然是函数也可以有返回值。
int main(){.......}表示main执行完成后返回一整型数。故return 0;就是main()执行完后返回一个0.
2、如果把int main{...}改为 void mian{...}就表示不返回数据,如果这样就必须去掉语句return 0;否则出错
3、while循环是要求用户输入两个整数,然后打印它们的和。不断的执行,直到用户按 ctrl+Z 才退出。所以这里EOF不是文件结束的意思,表示用户必须按Ctrl+Z 才能退出循环
下图是该程序的执行...