题目名称:计算器
题目描述:
* 编写程序,读入一行恰好包含一个加号、减号或乘号的表达式,输出它的值。
* 这个运算符保证是二元运算符,且两个运算符均不超过100的非负整数。
* 运算符和运算符可以紧挨着,也可以用一个或多个空格、TAB隔开。行首末尾均可以有空格。
* 样例输入: 1+1
* 样例输出: 2
* 样例输入: 2- 5
* 样例输出: -3
* 样例输入: 0 *1982
* 样例输出: 0
题目描述:
* 编写程序,读入一行恰好包含一个加号、减号或乘号的表达式,输出它的值。
* 这个运算符保证是二元运算符,且两个运算符均不超过100的非负整数。
* 运算符和运算符可以紧挨着,也可以用一个或多个空格、TAB隔开。行首末尾均可以有空格。
* 样例输入: 1+1
* 样例输出: 2
* 样例输入: 2- 5
* 样例输出: -3
* 样例输入: 0 *1982
* 样例输出: 0
#include <stdio.h>
int main()
{
int a,b,c;
char oper;
scanf("%d",&a);
do{
oper=getchar();
}while(!( oper=='+' || oper=='-' || oper=='*'));
scanf("%d",&b);
if(oper=='+')
c=a+b;
if(oper=='-')
c=a-b;
if(oper=='*')
c=a*b;
printf("%d",c);
return 0;
}