Binom
Thi function calculates the binomial coefficients.
Usageans = Binom( n=10, k=2, kind=1.0_Real32 )
- ܀ See Interface
- ܀ See example
- ↢ Close
INTERFACE
MODULE PURE FUNCTION Binom(n, k, kind) RESULT(ans)
INTEGER(Int8 | Int16 | Int32 | Int64), INTENT(IN) :: n
!! n is integer, should be a positive number and greater or equal to k
INTEGER(Int8 | Int16 | Int32 | Int64), INTENT(IN) :: k
!! k should be less than or equal to n
REAL(Real32 | Real64), INTENT(IN) :: kind
!! kind of output
REAL(Real32 | Real64) :: ans
END FUNCTION Binom
END INTERFACE
- The input arguments
n
andk
can beInt8, Int16, Int32, Int64
- The output is always a real number
- If kind is
Real32
then the output isReal32
- If the kind is
Real64
then the output isReal64
This example shows the usage of Binom method.
program main
use easifembase
implicit none
Here we are calculating , for
call display( Binom(4, 0, kind=1.0_DFP), "(4, 0) = " )
call display( Binom(4, 1, kind=1.0_DFP), "(4, 1) = " )
call display( Binom(4, 2, kind=1.0_DFP), "(4, 2) = " )
call display( Binom(4, 3, kind=1.0_DFP), "(4, 3) = " )
call display( Binom(4, 4, kind=1.0_DFP), "(4, 4) = " )
Results
(4, 0) = 1.00000
(4, 1) = 4.00000
(4, 2) = 6.00000
(4, 3) = 4.00000
(4, 4) = 1.00000
end program main