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; +} +}