概述
目录
题目及要求
涉及到的知识点
代码示例
运行实例
题目及要求
编写程序,定义和调用如下函数:
double add(double x,double y);
double sub(double x, double y);
double mul(double x, double y);
double div(double x, double y);
求两个浮点数的和、差、积、商,要求通过函数指针回调函数。一行中输人两个浮点数,以空格间隔。分行输出两个浮点数的和、差、积、商。
涉及到的知识点
【C语言程序涉及】 指针
【编译软件】 Visual Studio
代码示例
#include <stdio.h>
double add(double, double);
double sub(double, double);
double mul(double, double);
double div(double, double);
int main(void) {
double num1, num2, result;
double (*pf)(double, double);
scanf_s("%lf%lf", &num1, &num2); // 编译软件是Dev c++则要把_s去掉
pf = add;
result = pf(num1, num2);
printf("%lfn", result);
pf = sub;
result = pf(num1, num2);
printf("%lfn", result);
pf = mul;
result = pf(num1, num2);
printf("%lfn", result);
pf = div;
result = pf(num1, num2);
printf("%lfn", result);
return 0;
}
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) {
return x / y;
}
#include <stdio.h>
double add(double, double);
double sub(double, double);
double mul(double, double);
double div(double, double);
int main(void) {
double num1, num2, result;
double (*pf)(double, double);
scanf_s("%lf%lf", &num1, &num2);
pf = add;
result = pf(num1, num2);
printf("%lfn", result);
pf = sub;
result = pf(num1, num2);
printf("%lfn", result);
pf = mul;
result = pf(num1, num2);
printf("%lfn", result);
pf = div;
result = pf(num1, num2);
printf("%lfn", result);
return 0;
}
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) {
return x / y;
}
运行实例
最后
以上就是搞怪月亮为你收集整理的【C编写程序设计】定义和调用如下函数:double add(double x,double y);double sub(double x, double y);double mul(double x)题目及要求 涉及到的知识点代码示例运行实例的全部内容,希望文章能够帮你解决【C编写程序设计】定义和调用如下函数:double add(double x,double y);double sub(double x, double y);double mul(double x)题目及要求 涉及到的知识点代码示例运行实例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复