The user enters a number which will get passed to the calcFactorial function. As long as the number is bigger than zero the loop will repeat. The number will be multiplied by whatever is stored in result. One will be subtracted from x each time the loop is repeated.
When I tested it the program only worked up to 12. After that I would be given the wrong number. Are the numbers too large? I'm not sure what the issue is.
#include <stdio.h>
long calcFactorial(int x){
long result = 1;
while(x > 0){
result *= x;
x--;
}
return result;
}
int main(){
int x;
printf("Enter a number: ");
scanf(" %d",&x);
printf("%d",calcFactorial(x));
}