From a7d5b5f7cbc6f5a9f410c2280c2755955c22bc62 Mon Sep 17 00:00:00 2001 From: Adriz1611 <86981845+Adriz1611@users.noreply.github.com> Date: Sat, 22 Oct 2022 08:49:14 +0530 Subject: [PATCH] Create nCr_&_nPr.py --- Python/nCr_&_nPr.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Python/nCr_&_nPr.py diff --git a/Python/nCr_&_nPr.py b/Python/nCr_&_nPr.py new file mode 100644 index 0000000..bf22da0 --- /dev/null +++ b/Python/nCr_&_nPr.py @@ -0,0 +1,27 @@ +def fact(k): + f = i = 1 + while i<=k: + f = i*f + i += 1 + return f + +def findperm(x, y): + num = fact(x) + den = fact(x - y) + perm = num / den + return perm + +def findcomb(x, y): + num = fact(x) + den = fact(x - y) + den = fact(y) * den + comb = num / den + return comb + +print("Enter the Value of n: ", end="") +n = int(input()) +print("Enter the Value of r: ", end="") +r = int(input()) + +print("\nPermutation (nPr) =", findperm(n, r)) +print("Combination (nCr) =", findcomb(n, r))