fork download
  1. #include <stdio.h>
  2. main ()
  3. {
  4. int factorial; /* current factorial value */
  5. int i; /* loop index */
  6. int n; /* loop until n factorial */
  7.  
  8. /* prompt for max factorial value */
  9. printf ("Enter number of factorials: ");
  10. scanf ("%i", &n);
  11.  
  12. factorial = 1; /* let's start at 1 */
  13.  
  14. /* loop from 1 to n */
  15. for (i = 1; i <= n; ++i)
  16. {
  17. /* compute and print each factorial */
  18. factorial *= i;
  19. printf ("\n %i ! = %i", i, factorial);
  20.  
  21. } /* end for */
  22.  
  23. return (0);
  24. }
  25.  
Success #stdin #stdout 0.01s 5272KB
stdin
10
stdout
Enter number of factorials: 
 1 ! = 1
 2 ! = 2
 3 ! = 6
 4 ! = 24
 5 ! = 120
 6 ! = 720
 7 ! = 5040
 8 ! = 40320
 9 ! = 362880
 10 ! = 3628800