From 5fd80942f4ca3ab84fc02c96295c0ae3e27854fe Mon Sep 17 00:00:00 2001 From: Leon Wolf Date: Thu, 8 Feb 2024 19:10:51 +0100 Subject: [PATCH] calculate Factorial function added --- src/calculateFactorial.c | 19 +++++++++++++++++++ src/calculateFactorial.h | 8 ++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/calculateFactorial.c create mode 100644 src/calculateFactorial.h diff --git a/src/calculateFactorial.c b/src/calculateFactorial.c new file mode 100644 index 0000000..adb19d0 --- /dev/null +++ b/src/calculateFactorial.c @@ -0,0 +1,19 @@ + + +#include "calculateFactorial.h" + +int calculateFactorial_integer(int n) { + if (n < 0) { + + } else if (n == 0 || n == 1) { + + return 1; + } else { + + int result = 1; + for (int i = 2; i <= n; ++i) { + result *= i; + } + return result; + } +} diff --git a/src/calculateFactorial.h b/src/calculateFactorial.h new file mode 100644 index 0000000..f48849b --- /dev/null +++ b/src/calculateFactorial.h @@ -0,0 +1,8 @@ + + +#ifndef THEADMIRALS_CALCULATEFACTORIAL_H +#define THEADMIRALS_CALCULATEFACTORIAL_H + +int calculateFactorial_integer(int n); + +#endif //THEADMIRALS_CALCULATEFACTORIAL_H