! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 4.16. (File output.) Print divisors of all integers from 1 to Limit.
  program E16
    implicit none
    integer :: N, Limit, I
! start program E16
    open (unit = 2, file = "e16.zzz", status = "new", action = "write")
    write (unit = *, fmt = *) " Please enter limit for table of divisors. "
    read (unit = *, fmt = *) Limit
  A: do N = 1, Limit
      write (unit = 2, fmt = *) " Divisors of: ", N
    B: do I = 1, floor( sqrt( real( N ) ) )
        if (modulo( N, I ) == 0) then
          if (I ** 2 == N) then
            write (unit = 2, fmt = *) I
          else
            write (unit = 2, fmt = *) I, N / I
          end if
        end if
      end do B
    end do A
    stop
  end program E16
