Skip to content

Commit

Permalink
Permutaiton by defining function and using it
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Feb 2, 2024
1 parent 0cf714d commit b450003
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions permutaitonusingfunction.java
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);

}
}

0 comments on commit b450003

Please sign in to comment.