如何利用c语言编出加减乘除的编程
1个回答
展开全部
这个加减乘除的功能有要求么,不需要弹出计算器一样的吧?
#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");
}
}
#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");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询