#include"stdio.h"
#include"stdlib.h"
#include"math.h"
double f(double x,double a,double b,double c,double d,double e)
{
return a*x*x*x*x+b*x*x*x+c*x*x+d*x+e;
}
double integ(long n,double x0,double x1,double a,double b,double c,double d,double e)
{
double len=x1-x0,sum;
long i;
for(i=0;i<n;i++) sum=sum+f(x0+i/n*len,a,b,c,d,e);
printf("%lf\n",sum*len/n);
return sum*len/n;
}
main()
{
double reslt,prev,x1,x0,a,b,c,d,e;
long n=10;
scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&x0,&x1);
reslt=(x1-x0)*f(x0,a,b,c,d,e);
do{
prev=reslt;
reslt=integ(n,x0,x1,a,b,c,d,e);
n=n*10;
}while((fabs(reslt-prev)/prev)>0.01);
printf("%.4lf\n",reslt);
}
输入0,0,0,1,0,10,12
标准答案是21.9800,但我的答案是22.2000
[此贴子已经被作者于2016-12-21 18:38编辑过]