Java Code to Find ncR nPr - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, September 25, 2017

Java Code to Find ncR nPr

Write a Java Code to Find ncR nPr

Program:
/* Java Program Example - Find ncR nPr */

import java.util.Scanner;

public class JavaProgram
{
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 the valve of n:7
Enter the valve of r:3
NCR=35

NPR=210

No comments:

Post a Comment