-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permutaiton by defining function and using it
- Loading branch information
1 parent
0cf714d
commit b450003
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import java.util.*; | ||
public class Program | ||
{ | ||
public static void display(int n,int r,int npr) | ||
{ | ||
System.out.println(n+" P "+r+" is "+npr); | ||
|
||
} | ||
|
||
|
||
public static int fact(int x)//public static used to define the function | ||
//fact(int x) defined in such a way that x is the input value | ||
{ | ||
//function written detailed | ||
int fact=1; | ||
for(int i=1;i<=x;i++) | ||
{ | ||
fact=fact*i; | ||
} | ||
return fact; | ||
//returning the function value | ||
} | ||
public static void main(String[] args) | ||
{ | ||
Scanner scn=new Scanner(System.in); | ||
int n=scn.nextInt(); | ||
int r=scn.nextInt(); | ||
//taking input | ||
int nfact=fact(n); | ||
int nmrfact=fact(n-r); | ||
int npr=nfact/nmrfact; | ||
display(n,r,npr); | ||
|
||
} | ||
} |