Write a Java program to find the binomial co-efficient using recursion.

Posted by Crniranjanraj under Others on 10/5/2015 | Points: 10 | Views : 2297 | Status : [Member] | Replies : 1
Write a Java program to find the binomial co-efficient using recursion.




Responses

Posted by: Rajnilari2015 on: 10/12/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
public class Binomial
{
private static long binomial(int n, int k)
{
if (k>n-k)
k=n-k;

long b=1;
for (int i=1, m=n; i<=k; i++, m--)
b=b*m/i;
return b;
}

public static void main(String[] args)
{
System.out.println(binomial(5, 3));
}
}


Source: http://rosettacode.org/wiki/Evaluate_binomial_coefficients#Java

--
Thanks & Regards,
RNA Team

Crniranjanraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response