#include <stdio.h>
#include <math.h>
double (* funuk)(double);
double integral(double(*funuk)(double),
double a,double b,double eps)
{int i,n,k;
double s1,s2,x,d;
n=5;
d=(b-a)/n;
s2=1.0e+10;
k=0;
do
{s1=s2;
s2=0;n=n*2;
d=d/2;
x=a;k++;
for(i=1;i<=n;i++)
{ s2=s2+funuk(x);
   x=x+d;
 }
  s2=s2*d;

} while(fabs(s2-s1)>eps);
 return s2;
}
double f1(double x)
{return x*x-1;}
double f2(double x)
{return 2*x;}
int main(int, char**)
{double a,b,eps;
puts("input a,b,eps for y=x^2-1");
scanf("%lf %lf %lf",&a,&b,&eps);
printf("Value integral= %10.5lf\n",integral(f1,a,b,eps));
puts("input a,b,eps for y=2*x");
scanf("%lf %lf %lf",&a,&b,&eps);
printf("Value integral= %10.5lf\n",integral(f2,a,b,eps));
    return 0;
}
