From 30fa69497e5c8865accd3a8a62347943d122da40 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 4 Feb 2024 21:07:21 +0100 Subject: [PATCH] factorial Funktion --- src/c/funktionen.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/c/funktionen.c b/src/c/funktionen.c index 8c8f0d2..bffcaeb 100644 --- a/src/c/funktionen.c +++ b/src/c/funktionen.c @@ -57,3 +57,17 @@ return 0; float power(float x, float y) { return pow(x, y); } + +// Function to calculate the factorial of a number +int factorial(int x) { +if (x >= 0) { +int result = 1; +for (int i = 1; i <= x; i++) { +result *= i; +} +return result; +} else { +printf("Error: Invalid input for factorial!\n"); +return 0; +} +}