      program bisect 

      implicit none
  	  real (8)::a,b,fa,fb,epsilon,m,fm
	  integer ::i,NMAX
	  real (8),external :: f

    1 print *, ' Enter xa:' 
      read *, a 
      print *, ' Enter xb:' 
      read *, b 

      if ( f(a)* f(b) .ge. 0 ) then 
           write(*,*) ' Enter another pair of a and b!' 
           goto 1
      end if 

      print *, ' Enter tolerance epsilon:' 
      read *, epsilon
      print *, ' Enter maximum iteration number:' 
      read *, NMAX 

      fa = f(a) 
      fb = f(b) 

      Do I=1, NMAX 
         m  = a + (b-a) /2.d00 
         fm = f(m) 
         print *, i, a, b, m, fm  
         if( dabs((b-a) /2.d00) .lt. epsilon ) then 
             write(*,*)' **** Method has converged! '  
             stop
         end if 
         If( (fa*fm) .lt. 0.d00 ) then 
             b  = m 
             fb = fm 
         else
             a  = m 
             fa = fm 
         end if 
      end do 

      end

      real function F(X)
      implicit none
	  real (8)::x
      F = x - DCOS(x)
      return
      end



