#include "math.h"
double f(double x) /*定义被积函数*/
{
return x*x+3*x+2;
}
double integrate(double a,double b) /*定义积分公式函数*/
{double t,h;
int i,n=100;
t=0.5*(f(a)+f(b));
h=fabs(a-b)/n;
for(i=1;i<n;i++)
t+=f(a+i*h);
t=t*h;
return t;
}
void main() /*定义主函数*/
{printf("\n%f\n",integrate(0,2));}
参考资料:百度文库