作业帮 > 综合 > 作业

急 C语言 自定义函数,完成任意两个实数的四则运算

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 19:04:49
急 C语言 自定义函数,完成任意两个实数的四则运算
自定义函数,完成任意两个实数的四则运算.主函数中输出计算结果.函数头为:double fun(double x,double y,char z) 其中:x,y接受两个实数.Z接受一个运算符.
// 自定义函数,完成任意两个实数的四则运算.
// 主函数中输出计算结果.
// 函数头为:double fun(double x,double y,char z)
// 其中:x,y接受两个实数.Z接受一个运算符.
#include
#include
double fun(double x,double y,char z)
{
double ret = 0.0;
switch(z)
{
case '+':
ret = x + y;
break;
case '-':
ret = x - y;
break;
case '*':
ret = x * y;
break;
case '/':
ret = x / y;
break;
}
return ret;
}
int main()
{
double x;
double y;
char z;
printf("input :");
scanf("%lf%c%lf",&x,&z,&y);
printf("result:%lf",fun(x,y,z));
return 0;
}