Algorithm to find ncr and npr recursive using function
Answers
Answered by
0
public class PermComb { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Insert n"); int n=input.nextInt(); System.out.println("Insert r"); int r=input.nextInt(); double C = factorial(n)/(factorial(n-r)*factorial(r)); //Finding C. System.out.println("Therefore: nCr = " + C); double P = factorial(n)/(factorial(n-r)); //Finding P. System.out.println("Therefore: nPr = " + P); } public static double factorial(double num) { if(num==1) return 1; else return num = factorial(num-1)*num; }
Similar questions