求定积分y=1/(1+x^2 ) [0,1]用梯形法,结果不对求大神?????
# include <stdio.h>
# define n 100000000
# define h 1/n
double f(double x)
{ double y;
y=1/(1+x*x);
return y;
}
void main()
{ int i;
double f(double x);
double s=0;
for(i=1;i<n;i++)
{
s+=f(i*h);
}
s=(3/4+s)*h;
printf("%lf\n",s);
}
# define n 100000000
# define h 1/n
double f(double x)
{ double y;
y=1/(1+x*x);
return y;
}
void main()
{ int i;
double f(double x);
double s=0;
for(i=1;i<n;i++)
{
s+=f(i*h);
}
s=(3/4+s)*h;
printf("%lf\n",s);
}