V.2 Find Binomial Coefficient using Factorial Function Java Programming Code

Find Binomial Coefficient using Factorial Function Java Programming Code

public class BinCoeff {

    public static int factorial(int n) {
        int f = 1;
        for (int i = 1; i <= n; i++) {
            f = f * i;
        }
        return f; // factorial of n.
    }

    public static int BinCoeff(int n, int r) {
        int fact_n = factorial(n);
        int fact_r = factorial(r);
        int fact_nmr = factorial(n - r);
        int BinCoeff = fact_n / (fact_r * fact_nmr);
        return BinCoeff;
    }

    public static void main(String[] args) {
        System.out.println(BinCoeff(5, 2));

    }
}

🤭

No comments:

Post a Comment

Max Sub Array Sum: Kadane's Algorithm

Code of: Max Sub Array Sum: Kadane's Algorithm. public class MaxSubArraySumKadanesALgorithm {     public static void Kadane ( int ...