杭电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. 
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)
其实我也不怎么懂

转载于:https://www.cnblogs.com/woderenshengluwozijizou/p/4441764.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值