program enshu11aaf                        
implicitnone
real::x,y,ya,yb
real::a,b,verysmall
integer::n
a=1.0
b=10.0
verysmall=1.0e-2
ya=my_kansuu(a)
yb=my_kansuu(b)
if(ya*yb>0.0)stop
don=1,99
x=0.5*(a+b)
y=my_kansuu(x)
write(*,*)n,x,abs(x-sqrt(2.0)),a,b,y
if(b-a<verysmall)exit
if(y*ya>0.0)then
a=x
ya=y
else
b=x
yb=y
endif
enddo
write(*,*)n,x,abs(x-sqrt(2.0))
contains
functionmy_kansuu(z)
real,intent(in)::z
real::my_kansuu
my_kansuu=z**2-2.0
endfunctionmy_kansuu
endprogramenshu11aaf