十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#include
double add(double x, double y)//加
{
return x + y;
}
double sub(double x, double y)//减
{
return x - y;
}
double mul(double x, double y)//乘
{
return x*y;
}
double div(double x, double y)//除
{
if (y != 0)
{
return x/y;
}
else
{
printf("输入错误");
return -1;
}
}
void menu()
{
printf("************************\n");
printf("***1.add 2.sub***\n");
printf("***3.mul 4.div***\n");
printf("******* 0..exit ********\n");
printf("************************\n");
}
int main()
{
int input = 1;
double a = 0;
double b = 0;
double ret;
double(*p[5])(double a, double b) = { 0, add, sub, mul, div };
while (input)
{
menu();
printf("请输入需要的操作:\n");
scanf("%d",&input);
if (input > 0 && input <= 4)
{
printf("请输入操作数:\n");
scanf("%lf%lf",&a,&b);
ret = (*p[input])(a, b);
printf("%.2lf\n", ret);
}
else if (0==input)
{
break;
}
else
{
printf("输入错误");
}
}
return 0;
}