问题描述 : Calculate a + b
(问题来源https://zoj.pintia.cn/problem-sets/91827364500/problems):
Time Limit: 2000 ms Memory Limit: 65536 KB
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
Sample Output
6
Hint
Use + operator
Sample Program Here
错误解法一:
/* 仅能计算一对整型数据之和*/
# include <stdio.h>
int main()
{
int a;
int b;
//int c; 整型变量c 可去
scanf("%d %d", &a, &b);
//c = a+b;
printf("%d\n",a+b);
//printf("%d\n",c);
return 0;
}
不达标解法二(超时):
//计算一对或多对整型数据之和,并分行输出
# include <stdio.h>
int main(void) //如果不需要从命令行中获取参数,使用int main(void);否则使用int main(int argc, char *argv[])
{
int a,b;
scanf("%d %d",&a,&b);
while(a||b) // 符号 || 为逻辑或运算符, if(表达式1 || 表达式2)其中一个表达式为真,则满足 if 判定语句
{
printf("%d\n",a+b);
scanf("%d %d",&a,&b);
}
return 0;
}
不达标解法三(超时):
#include<stdio.h>
int main()
{
int a,b;
int i=0;
while(i!=-1) //符号 != 为不等于运算符
{
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
i++;
}
}
正确解法:
补充资料 :
void :
(https://en.wikipedia.org/wiki/Void_type