#include <iostream>
#include <cmath>
using namespace std;
double f(double x){
return 1+x;
}
double f2(double x){
return (3+x)*x;
}
double f3(double x){
return (exp(x)+1);
}
double integral(double a,double b,double(*f)(double)){
double ans=0;
for(int i=1;i<=100000;i++){
ans+=((b-a)/100000)*(f(a+(b-a)*i/1e5));
}
return ans;
}
int main(){
double (*p[3])(double);
p[0]=f;
p[1]=f2;
p[2]=f3;
for(int i=0;i<3;i++)
cout<<integral(0,1,p[i])<<endl;
}
定积分&&函数指针
最新推荐文章于 2021-12-03 16:22:21 发布