From 51938fda6bef75745c52a12168bf943d7ae9bfcc Mon Sep 17 00:00:00 2001 From: Eyal Royee Date: Fri, 25 Oct 2019 14:01:01 +0300 Subject: [PATCH] Implemented factorial in C. Signed-off-by: Eyal Royee --- Algorithms/Maths/factorial/factorial.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Algorithms/Maths/factorial/factorial.c diff --git a/Algorithms/Maths/factorial/factorial.c b/Algorithms/Maths/factorial/factorial.c new file mode 100644 index 00000000..b6c0e113 --- /dev/null +++ b/Algorithms/Maths/factorial/factorial.c @@ -0,0 +1,21 @@ +#include + +int factorial(int n) +{ + int result; + + if (0 == n) { + result = 1; + } else { + result = n * factorial(n - 1); + } + + return result; +} + +int main(int argc, char **argv) +{ + printf("The factorial of 3 is: %d\n", factorial(3)); + + return 0; +}