当前位置:网站首页>PTA:6-73 函数调用
PTA:6-73 函数调用
2022-06-23 03:47:00 【Sy_Faker】
编写三个函数:求两个整数的最大值、最小值、和。分别用这三个函数作为实参,再写一个计算函数compute,对两个整数进行各种计算。其中一个形参为指向具体算法函数的指针。
函数接口定义:
int max(int a, int b);
int min(int a, int b);
int sum(int a, int b);
int compute(int a, int b, int(*func)(int, int));
裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
#include <iostream>
using namespace std;
int max(int a, int b);
int min(int a, int b);
int sum(int a, int b);
int compute(int a, int b, int(*func)(int, int));
int main()
{
int a, b, res;
cin >> a >> b;
res = compute(a, b, & max);
cout << "Max of " << a << " and " << b << " is " << res << endl;
res = compute(a, b, & min);
cout << "Min of " << a << " and " << b << " is " << res << endl;
res = compute(a, b, & sum);
cout << "Sum of " << a << " and " << b << " is " << res << endl;
return 0;
}
/* 请在这里填写答案 */
输入样例:
3 5
输出样例:
Max of 3 and 5 is 5
Min of 3 and 5 is 3
Sum of 3 and 5 is 8
主要内容:指向函数的指针的运用
int max(int a, int b)
{
return a>b?a:b;
}
int min(int a, int b)
{
return a>b?b:a;
}
int sum(int a, int b)
{
return a+b;
}
int compute(int a, int b, int(*func)(int, int))
{
return (*func)(a,b);
}
边栏推荐
- [advanced binary tree] AVLTree - balanced binary search tree
- Prince language on insect date class
- [tcapulusdb knowledge base] [list table] delete all data sample codes in the list
- Implementation of VGA protocol based on FPGA
- Online JSON to CSharp (c) class tool
- 华为联机对战服务玩家快速匹配后,不同玩家收到的同一房间内玩家列表不同
- Preface
- Imitation 360 desktop suspended ball plug-in
- Can MySQL be used in Linux
- Questions about SQL statements
猜你喜欢

Halcon胶线检测—模板匹配、位姿变换、胶宽,胶连续性检测

Pytoch --- use pytoch's pre training model to realize four weather classification problems

无线网络安全的12个优秀实践
![[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime](/img/a9/11bc00a91b79358f28ada2d4c99f32.png)
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime

Redis启动有问题

Latest programming language rankings

Svg+js smart home monitoring grid layout

Background ribbon animation plug-in ribbon js

【一起上水硕系列】Day Three - preview4

炫酷鼠标跟随动画js插件5种
随机推荐
Bug STM32 interrupt (everyone knows)
How the innovative use of adobe international certification 𞓜 3D changes the entire industry
bubble sort
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
Web page dynamic and static separation based on haproxy
[tcapulusdb knowledge base] [list table] sample code for inserting data into the specified position in the list
PTA: Simulation Implementation of 7-87 set (class template)
Form development mode
虫子 STM32 高级定时器 (哈哈我说实话硬件定时器不能体现实力,实际上想把内核定时器发上来的,一想算了,慢慢来吧)
Can MySQL be used in Linux
华为联机对战服务玩家快速匹配后,不同玩家收到的同一房间内玩家列表不同
Imitation 360 desktop suspended ball plug-in
P1347 排序(topo)
【二叉树进阶】AVLTree - 平衡二叉搜索树
[tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
给你的AppImage创建桌面快捷方式
PTA:7-86 集合的模拟实现(函数模板)
What is the APM tool skywalking
IDEA-导入模块
How to solve the problem that the web page fails to log in after the easycvr service is started?