easy method Find Binomial Coefficient using Factorial Function Java Programming Code
public class BinomialCoefficient {
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 void main(String[] args) {
int n = 5, r = 2;
int nmr = n - r;
int factN = factorial(n);
int factR = factorial(r);
int factNMR = factorial(nmr);
int BinCo = factN / (factR * factNMR);
System.out.println(BinCo);
}
}
fghd
No comments:
Post a Comment