fork download
  1.  
  2. /*
  3. *
  4. * Factorial!: Computes the factorial of a positive integer
  5. *
  6. */
  7. #include <stdio.h>
  8. int main()
  9. {
  10. /* Initialization */
  11. int factorial; /* input to be entered by the user */
  12. int result; /* result, factorial! */
  13. printf("Please enter a number: ");
  14. scanf("%d", &factorial);
  15. int i;
  16. /* Compute factorial */
  17. result = 1;
  18. for (i = factorial; i > 0; i = i-1) {
  19. result *= i;
  20. }
  21. /* Print the answer */
  22. printf("%d\n", result);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Please enter a number: 0