指针指向函数作为参数

`#include
#include
#include
using namespace std;

double func1(double x)
{
double r=1+x;
return r;
}
double func2(double x)
{
double r=x*2+3;
return r;
}
double func3(double x)
{
double r=1+exp(x);
return r;
}
double func4(double x)
{
double r=pow((1+x),2);
return r;
}
double func5(double x)
{
double r=pow(x,3);
return r;
}

int main()
{
double a,b;
cout<<“input:”;
cin>>a>>b;
double temp=0;
double jd=10000;
double fd=(a+b)/jd;

double func5(double x);//
double(*p)(double);//
p=func5;//
for(double i=a;i<=b;i+=fd)
{
	
	temp=p(i)*fd+temp;//
}

cout<<"result="<<temp<<endl;
return 0;

}
`

上一篇:python 练习题


下一篇:C++学习笔记(一):变量、常量和命名规则