当前位置:网站首页>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);
}
边栏推荐
- 怎么用好MySQL索引
- mysql,字段问题
- 怎样能在小程序中实现视频通话及互动直播功能?
- SVG+JS智能家居监控网格布局
- After Huawei online battle service players quickly match, different players receive different lists of players in the same room
- IDEA-导入模块
- 众昂矿业:新能源新材料产业链对萤石需求大增
- Avltree - arbre de recherche binaire équilibré
- Pytorch---Pytorch进行自定义Dataset
- leetcode 91. Decode ways (medium)
猜你喜欢

移动端城市列表排序js插件vercitylist.js

在word里,如何让页码从指定页开始编号

It supports running in kubernetes, adds multiple connectors, and seatunnel version 2.1.2 is officially released!

svg d3. JS generate tree tree view

Online text filter less than specified length tool

【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime

Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!

mysql如何删除表的一行数据

浅析2022年物联网现状

深度学习 简介
随机推荐
Flutter怎么实现不同缩放动画效果
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
怎样能在小程序中实现视频通话及互动直播功能?
浅析2022年物联网现状
Two ways to improve the writing efficiency of hard disk storage data
bubble sort
Twitter cooperates with Shopify to introduce merchant products into twitter shopping
[从零开始学习FPGA编程-40]:进阶篇 - 设计-竞争与风险Risk或冒险
Ideal car × Oceanbase: when new forces of car building meet new forces of database
Differences between MyISAM and InnoDB of MySQL storage engine
photoshop PS 查看像素坐标、像素颜色、像素HSB颜色
Bug STM32 interrupt (everyone knows)
关于sql语句的问题
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
Particle animation background login page particles js
[tcapulusdb knowledge base] [list table] sample code for inserting data into the specified position in the list
静态查找表和静态查找表
Pytorch---Pytorch进行自定义Dataset
【二叉树进阶】AVLTree - 平衡二叉搜索树
深度学习 简介