fork download
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. int factorialFun( int N );
  5.  
  6. int main(void) {
  7.  
  8. int N;
  9. printf("Enter a number you wish to know the factorial of\n");
  10. scanf("%d", &N);
  11. int factorial = factorialFun( N );
  12. printf("%d! = %d", N, factorial);
  13. return 0;
  14. }
  15.  
  16.  
  17.  
  18. int factorialFun( int N )
  19. {
  20. int fact = N;
  21. for( int i = N; i > 1; i-- )
  22. {
  23.  
  24. fact = fact * (i - 1);
  25.  
  26. printf("%d ", i);
  27. }
  28. return fact;
  29. }
  30.  
  31.  
Success #stdin #stdout 0s 9432KB
stdin
3
stdout
Enter a number you wish to know the factorial of
3 2 3! = 6