运算符判定
Description
两个整数 a 和 b 运算后得到结果 c。表示为:a ? b = c,其中,?可能是加法 +,减法 -,乘法 *,整除 / 或 取余 %。请根据输入的 a,b,c 的值,确定运算符。如果某种运算成立,则输出相应的运算符,如果任何运算都不成立,则输出 error.
Input
a b和 c 的值在意行内输入,以逗号间隔
Output
五个运算符之一或 error
Sample Input 1
3,4,5
Sample Output 1
error
Sample Input 2
3,4,3
Sample Output 2
%
Hint
不考虑输入的数字同时满足两个运算符的情况
代码如下:
1 #include<stdio.h>
2 int main()
3 {
4 int a,b,c;
5 scanf("%d,%d,%d",&a,&b,&c);
6 if (a+b ==c)
7 {
8 printf("+\n");
9 }
10 else
11 if (a-b ==c)
12 {
13 printf("-\n");}
14 else
15 if (a*b ==c)
16 {
17 printf("*\n");}
18 else
19 if (b !=0&&a/b ==c)
20 {
21 printf("/\n");
22 }
23 else
24 if (b !=0&&a%b ==c)
25 { printf("%c\n",'%');
26 }
27 else
28 printf("error\n");
29 return 0;
30 }
举例:
实测: