Java Binomial Coefficients binomial(int n, int k)

Here you can find the source of binomial(int n, int k)

Description

Returns binomial coefficient

License

Open Source License

Parameter

Parameter Description
n a parameter
k a parameter

Declaration

public static int binomial(int n, int k) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//www.j av  a  2  s.com
     * Returns binomial coefficient
     *
     * @param n
     * @param k
     * @return
     */
    public static int binomial(int n, int k) {
        if (n < 0 || k < 0 || k > n)
            return 0;
        int res = 1;
        for (int i = k + 1; i <= n; i++)
            res *= i;
        for (int i = 2; i <= n - k; i++)
            res /= i;
        return res;
    }
}

Related

  1. binomial(final int n, final int k)
  2. binomial(int n, double p)
  3. binomial(int n, final int k)
  4. binomial(int N, int K)
  5. binomialCdf(int k, int n, double p)
  6. binomialCoeff(int n, int k)
  7. binomialCoefficient(double n, double k)
  8. binomialCoefficient(int n, int k)