uses crt,graph;
const a=-5.0;
      b=1.0;
      eps1=0.000001;
      eps2=0.000001;
type funct=function (x:real):real;
var rez1,rez2,rez3,itog:real;
    yn:char;

{$F+}
function f(x:real):real;
begin
 f:=exp(-x*x/10);
end;

function f1(x:real):real;
begin
 f1:=-0.2*x*exp(-x*x/10);
end;

function g(x:real):real;
begin
 g:=sqrt(-x)
end;

function g1(x:real):real;
begin
 g1:=-0.5/sqrt(-x);
end;

function l(x:real):real;
begin
 l:=x+0.1
end;

function l1(x:real):real;
begin
 l1:=1;
end;


function root(f,f1,g,g1:funct; a,b:real; eps:real):real;
var c1,c2:real;
begin
repeat
 c1:=f(a)-g(a);
 c2:=f(b)-g(b);
 b:=(a*c2-b*c1)/(c2-c1);
 if abs(a-b)>eps then
  a:=a-c1/(f1(a)-g1(a));
until abs(a-b)<eps;
root:=(a+b)/2;
end;

function integral(f,g:funct;a,b:real;eps:real):real;
var h,Sn,Sn1,c:real;
    flag:boolean;
begin
h:=b-a;
Sn1:=((abs(f(a)-g(a)))+(abs(f(b)-g(b))))/2;
if a>=b then flag:=true
 else flag:=false;
repeat
 Sn:=Sn1;
 c:=a+h/2;
 repeat
  Sn1:=Sn1+(f(c)-g(c));
  c:=c+h
 until (not(flag) and (c>=b)) or (flag and (c<=b));
 h:=h/2;
 until abs(Sn1*h-Sn*h*2)<=eps;
integral:=abs(Sn1*h);
end;



begin
 clrscr;
 rez1:=root(f,f1,g,g1,-1.0,-0.8,eps1);
 rez2:=root(f,f1,l,l1,0.7,0.9,eps1);
 rez3:=root(g,g1,l,l1,-0.01,-0.001,eps1);
 writeln('tochki peresecheniya:');
 writeln('f1 i f2: ', rez1:10:6);
 writeln('f1 i f3: ', rez2:10:6);
 writeln('f2 i f3: ', rez3:10:6);
 itog:=integral(f,l,rez2,rez3,eps2)+integral(f,g,rez3,rez1,eps2);
 writeln;
 writeln('square = ', itog:10:6);
 readln;


end.