Untitled
unknown
plain_text
a year ago
964 B
3
Indexable
/* to calculate binomial coefficient of nCr. nCr = n!/ r! (n-r)! */ import java.util.*; public class Functions6{ public static long factorial(long x){ long f = 1; for (long i=1; i<=x; i++){ f= f*i; } return f; } public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.print(" value of N in nCr: "); long n = sc.nextLong(); System.out.print(" value of R in nCr: "); long r = sc.nextLong(); if (n>=r){ long diff = n-r; long nFact = factorial(n); long rFact = factorial(r); long diffFact = factorial(diff); double nCr = nFact/((rFact)*(diffFact)); System.out.println("The value of the nCr is: " + (nCr)); } else{ System.out.println("this binomial coeff doesn't exists. "); } } }
Editor is loading...
Leave a Comment