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