C Library Functions - 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
|
n |
number of objects
|
|
r |
number of the objects to select in a set
|
|
ncomp |
returns number of unique combinations
|
|
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
n=10
r=2
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
Results:
ncr = 45.000000
AUTHOR
Alan Miller
| Nemo Release 3.1 | ncr (3) | June 29, 2025 |
Generated by manServer 1.08 from 4a973767-de6e-48fd-a0ce-33e04a328d27 using man macros.