Here you can find the source of binomial(int n, int k)
Parameter | Description |
---|---|
n | a parameter |
k | a parameter |
public static int binomial(int n, int k)
//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; } }