用C语言设计一个计算器,可以进行简单的加减乘除运算,用嵌套实现
1个回答
2012-11-11
展开全部
#include <stdio.h>
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();
}
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询