Browse Source

factorial Funktion

remotes/origin/Abdelrahman
Abdelrahman 11 months ago
parent
commit
30fa69497e
  1. 14
      src/c/funktionen.c

14
src/c/funktionen.c

@ -57,3 +57,17 @@ return 0;
float power(float x, float y) { float power(float x, float y) {
return pow(x, 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;
}
}
Loading…
Cancel
Save