简单的终端输入运算符计算小代码。。请问还有别的办法吗?
简单的终端输入运算符计算小代码。。gcc成功过。。请问还有别的办法吗?有没有新的思路办法?
代码***************************************
#include <stdio.h>
int main()
{ int a,b,sun;
float sun1;
char c;
printf("number one: ");
scanf("%d",&a);
printf("please Select:+,-,*,/,%%: " );
scanf("%s",&c);
printf("number two: ");
scanf("%d",&b);
sun=c;
switch(sun) {
case 43:sun1=a+b;break;
case 45:sun1=a-b;break;
case 42:sun1=a*b;break;
case 47:sun1=(float)a/b;break;
case 37:sun1=a%b;break;
default :printf("sorry\n");return 0; }
printf("%d %c %d = %.2f\n",a,c,b,sun1);
return 0;
}
***************************************************