用C语言设计一个计算器,可以进行简单的加减乘除运算,用嵌套实现

2024-11-01 00:01:08
推荐回答(1个)
回答1:

#include
int main()
{
float x,y;
char c;
printf("Input x:");
scanf("%f",&x);
printf("Input y:");
scanf("%f",&y);
printf("Celect (+,-,*,/):");
scanf("%c%c",&c,&c);
switch(c)
{
case '+':printf("%0.2f+%0.2f=%0.2f\n",x,y,x+y);break;
case '-':printf("%0.2f-%0.2f=%0.2f\n",x,y,x-y);break;
case '*':printf("%0.2f*%0.2f=%0.2f\n",x,y,x*y);break;
case '/':printf("%0.2f/%0.2f=%0.2f\n",x,y,x/y);
}
getch();
}