Open In App

Getting binomial coefficient of a number in Julia – binomial() Method

The binomial() is an inbuilt function in julia which is used to return the binomial coefficient which is the coefficient of the kth term in the polynomial expansion of . Its formula is –

   

, where is the factorial of n. If n is negative, then it is defined in terms of the identity

   

.
Syntax: binomial(n::Integer, k::Integer) Parameters:
  • n: Specified number
  • k: Specified number
Returns: It returns the binomial coefficient .
Example 1:
# Julia program to illustrate 
# the use of binomial() method
  
# Getting the binomial coefficient
println(binomial(6, 4))
println(factorial(6) ÷ (factorial(6-4) * factorial(4)))

                    
Output:
15
15
Example 2:
# Julia program to illustrate 
# the use of binomial() method
  
# Getting the binomial coefficient
println(binomial(6, 3))
println(binomial(-6, 3))
println(binomial(-6, -2))
println(binomial(5, 2))

                    
Output:
20
-56
0
10

Article Tags :