本程序通过函数指针调用,实现对sin、cos和tan的求值,理解函数指针数组的使用,最终完成程序填空并执行。
#include <math.h>
double execute (double x, 【 】)
{
double temp;
temp = 【 】;
return ((*func)(x));
}
main()
{
double 【 】;
double x=1;
int i;
function[0]=sin;
function[1]=cos;
function[2]=tan;
for (i=0; i<3; i++)
printf("func No: %d---%f\n", i+1, execute(x, 【 】);
}
这个需要用函数指针实现.
这几个函数都是 double sin(double)的形式, 所以函数指针为 double(*pfun)(double)
于是 结果如下:
#include <math.h>