用矩形法求定积分,输出结果全是零,不知道错在哪
#include <stdio.h>#include <math.h>
static double definite_integral(int a,int b,double (*p)(double));//a,b是定积分上下限
int main()
{
printf("sinx在0到1上的积分值是:%7.4lf\n",definite_integral(0,1,sin));
printf("cosx在0到1上的积分值是:%7.4lf\n",definite_integral(0,1,cos));
printf("e^x在0到1上的积分值是:%7.4lf",definite_integral(0,1,exp));
return 0;
}
static double definite_integral(int a,int b,double (*p)(double))
{
double fx=0;
double n;
double c,d;
for(n=1;n<=1000;n++)//矩形法求定积分的值
{
c=a+(b-a)/1000*n;
d=(*p)(c);
fx=fx+(b-a)/1000*d;
}
return fx ;
}