You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
677 B
32 lines
677 B
#include <stdio.h>
|
|
|
|
unsigned long long factorial(int n) {
|
|
if (n < 0) {
|
|
return 0; // Fakultät für negative Zahlen ist nicht definiert
|
|
}
|
|
|
|
unsigned long long result = 1;
|
|
|
|
for (int i = 1; i <= n; ++i) {
|
|
result *= i;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
int run_factorial() {
|
|
int num;
|
|
printf("Gib eine Zahl ein, um die Fakultät zu berechnen: ");
|
|
scanf("%d", &num);
|
|
|
|
unsigned long long result = factorial(num);
|
|
|
|
if (num < 0) {
|
|
printf("Fakultät ist für negative Zahlen nicht definiert.\n");
|
|
} else {
|
|
int result = factorial(num);
|
|
printf("Die Fakultät von %d ist %d.\n", num, result);
|
|
}
|
|
|
|
return 0;
|
|
}
|