#include <stdio.h>
int main()
{
float a,b;
char c;
printf("Please enter a,b and op:");
scanf("%f%c%f",&a,&c,&b);
switch(c)
{
case '+':
printf("%f+%f=%f\n",a,b,a+b);
break;
case '-':
printf("%f-%f=%f\n",a,b,a-b);
break;
case '*':
printf("%f*%f=%f\n",a,b,a*b);
break;
case '/':
if(b!=0.0)
printf("%f/%f=%f\n",a,b,a/b);
else
printf("error!\n");
break;
default:
printf("error!\n");
break;
}
return 0;
}
用switch语句实现多分支结构
最新推荐文章于 2024-03-24 13:19:22 发布