From d8e8de918d537e3bf762246c4eb9d32cf00d3c66 Mon Sep 17 00:00:00 2001 From: Ulriche Nguefack Date: Wed, 7 Feb 2024 14:44:24 +0100 Subject: [PATCH] refactoring: ending-permutation|combination --- src/main/c/Calculator/calculator.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/c/Calculator/calculator.c b/src/main/c/Calculator/calculator.c index 8d4cdc8..5110e69 100644 --- a/src/main/c/Calculator/calculator.c +++ b/src/main/c/Calculator/calculator.c @@ -128,6 +128,17 @@ double factorial(double num) { return num * factorial(num - 1); } } +double permutation(int n, int r) { + double result = 1; + for (int i = 0; i < r; i++) { + result *= (n - i); + } + return result; +} + +double combination(int n, int r) { + return permutation(n, r) / factorial(r); +} int getIntInput(const char *message) { int input;