[root@qq a]# cat a.sh
#!/bin/bash
#a.sh
read a ch b
case $ch in
+)echo "$a+$b=`expr $a + $b`";;
-)echo "$a-$b=`expr $a - $b`";;
/)echo "$a/$b=`expr $a \/ $b`";;
'*')echo "$a*$b=`expr $a \* $b`";;
%)echo "$a&$b=`expr $a % $b`";;
^)echo "$a^$b=$(($a**$b))";;
*)echo error;;
esac
[root@qq a]# cat a.c
main()
{
int a,b;
char c;
scanf("%d%c%d",&a,&c,&b);
switch(c)
{
case '+': printf("%d%c%d=%d\n",a,c,b,a+b);
break;
case '-': printf("%d%c%d=%d\n",a,c,b,a-b);
break;
case '*': printf("%d%c%d=%d\n",a,c,b,a*b);
break;
case '/': printf("%d%c%d=%d\n",a,c,b,a/b);
break;
default: printf("error\n");
}
}
阅读(965) | 评论(0) | 转发(0) |