PPT8-14 指向函数的指针作为函数参数.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《PPT8-14 指向函数的指针作为函数参数.pdf》由会员分享,可在线阅读,更多相关《PPT8-14 指向函数的指针作为函数参数.pdf(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、指向函数的指针作为函数参数 实例8.10定义长度为12的double 数组,数组存储数据如下: double a=1.5,3.8,5.6,7.8,91.6,1.61,13 .3,15.0,17.5,19.9,21.7,23.0; 函数指针案例讲解 编写函数实现下面的功能。 (1)求数组全部的元素值之和; (2)求数组元素中的最大值; (3)求下标为奇数的数组元素之和; (4)求各元素的平均值。 函数指针案例讲解 解题思路:分别设计4个函数实现上 述4个功能,使4个函数具有相同的 返回值类型、参数个数、参数顺序和 参数类型,唯一不同的就是函数的名 字和函数的具体实现,这样就可以使 用唯一个函数指
2、针先后调用这4个函 数实现题目要求。 函数指针案例讲解 arr_add(double arr,int n) odd_add(double arr,int n) arr_ave(double arr,int n) arr_max(double arr,int n) #include #define N 12 double arr_add(double arr,int n) double arr_max(double arr,int n) double odd_add(double *p, int n) double arr_ave(double *p,int n) arr_add(double
3、arr,int n) odd_add(double arr,int n) arr_ave(double arr,int n) arr_max(double arr,int n) void process(double *p,int n,double (*fun)(double *,int ) double result; result = (*fun)(p,n); printf(%8.2lfn,result); 123101112 a process(a,N,arr_add); a12arr_add 返回数组各元素之和,在 process中打印 arr_add(double arr,int n
4、) odd_add(double arr,int n) arr_ave(double arr,int n) arr_max(double arr,int n) void process(double *p,int n,double (*fun)(double *,int ) double result; result = (*fun)(p,n); printf(%8.2lfn,result); 123101112 a process(a,N,arr_max); a12arr_max 返回数组各元素的最大值, 在process中打印 arr_add(double arr,int n) odd_a
5、dd(double arr,int n) arr_ave(double arr,int n) arr_max(double arr,int n) void process(double *p,int n,double (*fun)(double *,int ) double result; result = (*fun)(p,n); printf(%8.2lfn,result); 123101112 a process(a,N,odd_add); a12odd_add 返回数组奇数下标元素之和, 在process中打印 arr_add(double arr,int n) odd_add(dou
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 森林经营规划
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内