Java Code to Find ncR nPr - Computer Programming


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

/* 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.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))));

Enter the valve of n:7
Enter the valve of r:3


No comments:

Post a Comment