Tuesday 8 August 2017

Program to find ncR and npR values

import java.util.Scanner;

public class nCrAndnPr
{
    public static int fact(int num)
    {
        int fact=1, i;
        for(i=1; i<=num; i++)
        {
            fact = fact*i;
        }
        return fact;
    }
    public static void main(String args[])
    {
        int n, r;
        Scanner scan = new Scanner(System.in);

        System.out.print("Enter Value of n : ");
        n = scan.nextInt();
        System.out.print("Enter Value of r : ");
        r = scan.nextInt();

        System.out.print("NCR = " +(fact(n)/(fact(n-r)*fact(r))));
        System.out.print("\nNPR = " +(fact(n)/(fact(n-r))));

    }
}





OUTPUT:

Enter Value of n : 10
Enter Value of r : 2
NCR = 45

NPR = 90

No comments:

Post a Comment