1原理是字符串的识别以及switch的用法
#include <stdio.h>
int main(void)
{
//=======begin=======
float a=0;
float b=0;
char c=0;
double x=0;
scanf ("%f %c %f", &a,&c,&b);
switch (c)
{
case '+':
x=a+b;
printf ("%f + %f = %.6lf", a,b,x);
break;
case '-':
x=a-b;
printf ("%f - %f = %.6lf", a,b,x);
break;
case '*':
x=a*b;
printf ("%f * %f = %.6lf",a,b,x);
break;
case '/':
if (b==0)
printf ("Division by zero!");
else
{
x=a/b;
printf ("%f / %f = %.6lf", a,b,x);
}
break;
case '%':
if (b==0)
printf ("Division by zero!");
else
{
x=a%b;
printf ("%f %% %f = %.6lf", a,b,x);
}
break;
default: printf ("Invalid operator!");
break;
}
return 0;
}
//========end========