¡@

   program mid_ex_92

   implicit none

   integer              :: ii, low, high, search_key, search_result, &
                           middle, size
   integer, allocatable :: mtx_a(:)

   write(*,*) 'Enter the dimension of matrix A which is less than 1000'
   read (*,*) size

   allocate( mtx_a(size) )

   do ii = 1, size
      mtx_a(ii) = 2*(ii-1)
   end do

   write(*,30) size
30 format(2x,'Enter a number between 0 and ',I3,': ')
   read (*,*) search_key

   low           = 0
   high          = size
   search_result = -1

   do while ( low <= high .and. search_result == -1 )
      middle = ( low + high ) / 2;
      if ( search_key == mtx_a(middle) ) then
         search_result = middle
      elseif ( search_key < mtx_a(middle) ) then
         high          = middle - 1
      else
         low           = middle + 1
      end if
   end do

   if ( search_result /= -1 ) then
      write(*,10) search_key, search_result
10    format(2x, I3, ' found in array elemnet ', I3)
   else
      write(*,20) search_key
20    format(2x, I3,' not found')
   end if

   end program mid_ex_92
¡@