# include <math.h>
# include <stdio.h>
# define L 9
double f(double x)
{
return 1.0/(1.0+x*x);
}
double fc(double a,double b,double (*f)())
{
int m,n,i,k;
double y[L],h,ep,p,x,s,q;
h=b-a;
y[0]=h*((*f)(a)+(*f)(b))/2.0;
m=1;n=1;ep=1.0;
while((ep>=1e-10)||(m<=L)){
p=0.0;
for(i=0;i<=n-1;i++){
x=a+(i+0.5)*h;
p+=(*f)(x);
}
p=(y[0]+h*p)/2.0;
s=1.0;
for(k=1;k<=m;k++){
s*=4.0;
q=(s*p-y[k-1])/(s-1.0);
y[k-1]=p;p=q;
}
ep=fabs(q-y[m-1]);
m+=1;
y[m-1]=q;
n+=n;
h/=2.0;
}
return q;
}
main()
{
double a,b,t;
a=0.0;b=1.0;
t=fc(a,b,f);
printf("π=3.14159265358979323\n");
printf(" %.15f",t*4.0);
getch();
}