В следующем коде есть проблема, которую я не могу решить:
#include <stdio.h>
#include <stdlib.h>
int factorial(long long int x) {
long long int temp;
temp = x - 1;
for (; temp > 0; temp--) {
x = x * temp;
}
return x;
}
int main() {
long long int x, fact;
while (1) {
printf("Please enter the number that you want to learn factoriel...\n(To quit press ctrl+c)\n");
scanf("%lld", &x);
if (x == EOF) {
break;
}
if (x >= 0) {
fact = factorial(x);
printf("Factorial of %lld is %lld\n", x, fact);
} else {
fact = 0;
printf("Factorial of %lld is %lld\n", x, fact);
}
}
printf("The Program has successfully terminated...\n");
return 0;
}
Прежде всего, это работает до 17, но в 17 это дает мне отрицательный набор чисел в результате и пару числа позже это дает мне 0 в результате
Как мне это исправить?