real x,e,ss,h,sst
integer t,d
print*,'x='
read*,x
print*,'sai so='
read*,e
print*,'     buoc         x      f(x)      ss'
sst=1000.
ss=999.
t=1
d=0
do while (ss.gt.e)
  if (sst.gt.ss)  then
   sst=ss
   h=f(x)
   ss=abs(h-x)
   print 100,t,x,h,ss
   100 format(i4,3f20.4)
   x=h
   t=t+1
  else 
   print*,'khong hop le'
   ss=e-1
   d=1
  end if
end do
if (d.eq.0) print 99,x
 99 format('x=   ',f10.4)  
contains
function f(y) result (fx)
real y
fx =1/y
end function f
end