[UP]


Manual Reference Pages  - ncr (3)

NAME

ncr(3f) - [M_math] Calculate the number of unique combinations of r objects out of n.

CONTENTS

Synopsis
Description
Options
Example
Author

SYNOPSIS

subroutine ncr(n,r,ncomb,ier)

    integer, intent(in)     :: n
    integer, intent(in)     :: r
    !!integer, parameter      :: dp = selected_real_kind(12, 60)
    integer, parameter      :: dp = kind(0.0d0)
    real (dp), intent(out)  :: ncomb
    integer, intent(out)    :: ier

DESCRIPTION

Calculate the number of unique combinations of r objects out of n.

OPTIONS

ier returns error code
o 0 if no error is detected
o 1 if n < 1
o 2 if r < 0
o 3 if r > n
o 4 if nCr > 1.e+308, i.e. if it overflows. In this case, the natural log of nCr is returned.

EXAMPLE

Sample program:

   program demo_ncr
   use m_math, only : ncr
   implicit none
   integer, parameter  :: dp = selected_real_kind(12, 60)
   integer             :: n, r, ier
   real (dp)           :: result
   do
      write(*, ’(a)’, advance=’no’) ’ Enter n, r : ’
      read(*, *) n, r
      call ncr(n, r, result, ier)
      if (ier /= 0) then
         write(*, *) ’ Error, IER = ’, ier
         if (ier == 4) write(*, ’(a, f12.5)’) ’ ln(ncr) = ’, result
      else
         write(*, ’(a, g16.8)’) ’ ncr = ’, result
      endif
   enddo
   end program demo_ncr

AUTHOR

Alan Miller


ncr (3) October 17, 2020
Generated by manServer 1.08 from 17cc270c-d076-4cc5-b1bc-de206f4773f0 using man macros.