发布网友 发布时间:2022-04-22 05:24
共1个回答
热心网友 时间:2022-04-16 06:12
这个加减乘除的功能有要求么,不需要弹出计算器一样的吧?
#include<stdio.h>
void
main()
{
float
fValue1,fValue2;
char
cStr;
printf("请输入两个数值:\n");
scanf("%f",&fValue1);
scanf("%f",&fValue2);
printf("请输入相关操作(+
-
*
/)");
getchar();
scanf("%c",&cStr);
switch(cStr)
{
case
'+':
{
printf("%.2f+%.2f
=
%.2f\n",fValue1,fValue2,fValue1+fValue2);
break;
}
case
'-':
{
printf("%.2f-%.2f
=
%.2f\n",fValue1,fValue2,fValue1-fValue2);
break;
}
case
'*':
{
printf("%.2f*%.2f
=
%.2f\n",fValue1,fValue2,fValue1*fValue2);
break;
}
case
'/':
{
printf("%.2f/%.2f
=
%.2f\n",fValue1,fValue2,fValue1/fValue2);
break;
}
default:printf("对不起!没有相关操作运算~\n");
}
}