From b45000388ef8d1bf4bc1d8bc8beac5a6d6a879d0 Mon Sep 17 00:00:00 2001 From: Suhani Gupta <144280247+suhanigupta23@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:57:23 +0530 Subject: [PATCH] Permutaiton by defining function and using it --- permutaitonusingfunction.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 permutaitonusingfunction.java diff --git a/permutaitonusingfunction.java b/permutaitonusingfunction.java new file mode 100644 index 0000000..b93096a --- /dev/null +++ b/permutaitonusingfunction.java @@ -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); + + } +}