! 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 8.11. Calculate binomial coefficients as ratios of factorials.
  program I11
    use I11M
    implicit none
    integer :: N, R
! start program I11
    open (unit = 1, file = "i11.txt", status = "old", action = "read", position = "rewind")
    do
      read (unit = 1, fmt = *) N, R
      if ((R < 0) .or. (R > N)) then
        stop
      end if
      write (unit = *, fmt = *) " N = ", N, " R = ", R
      write (unit = *, fmt = *) " C = ", Factorial( N ) / (Factorial( R ) * Factorial( N - R ))
    end do
    stop
  end program I11
