operator=是什么意思啊# include double sum(double a,double b);double subtract(double a,double b);double divide(double a,double b);double multiply(double a,double b);main(){int choice;char operator;double a,b;double (*func)();printf("\n* * * * *
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 04:54:43
operator=是什么意思啊# include double sum(double a,double b);double subtract(double a,double b);double divide(double a,double b);double multiply(double a,double b);main(){int choice;char operator;double a,b;double (*func)();printf("\n* * * * *
operator=是什么意思啊
# include
double sum(double a,double b);
double subtract(double a,double b);
double divide(double a,double b);
double multiply(double a,double b);
main()
{
int choice;
char operator;
double a,b;
double (*func)();
printf("\n* * * * * 两个数四则运算计算器程序* * * * * * * * *");
printf("\n1.加");
printf("\n2.减");
printf("\n3.乘");
printf("\n4.除");
printf("\n要做哪种运算?(输入1、2、3或4,输入其他值将自动退出):");
choice=getchar();
switch(choice)
{
case '1':
func=sum;
operator='+';
break;
case '2':
func=subtract;
operator='-';
break;
case '3':
func=multiply;
operator='*';
break;
case '4':
func=divide;
operator='/';
break;
default:
return;
}
printf("\n\n请输入第一个数a :");
scanf("%lf",&a);
printf("\n\n请输入第二个数b :");
scanf("%lf",&b);
printf("\n 计算结果是:%lf %c %lf = %lf\n",a,operator,b,(*func)
(a,b));
}
double sum(double a,double b)
{
return a+b;
}
double subtract(double a,double b)
{
return a-b;
}
double multiply(double a,double b)
{
return a*b;
}
double divide(double a,double b)
{
return a/b;
}
这个程序里的operator=‘+’是不是说给这个函数+运算符的功能啊?
operator=是什么意思啊# include double sum(double a,double b);double subtract(double a,double b);double divide(double a,double b);double multiply(double a,double b);main(){int choice;char operator;double a,b;double (*func)();printf("\n* * * * *
这个operator只是一个变量,你完全可以将全文的operator换成别的名字
operator='+'仅仅是用于最后的输出工作,即:
printf("\n 计算结果是:%lf %c %lf = %lf\n",a,operator,b,(*func)(a,b));
其他地方不起作用.
外加说明下:这段代码在C++里调试是出错的,C++中operator是关键字,还有
double (*func)();
这里指向函数的指针要配对参数,如:
double (*func)(double,double);