#include main () { int n, i = 0; printf ("Please enter the value of n: "); scanf ("%d", &n); if (n >= 0) { while (n >= 0) { /* output all n factorials */ printf ("factorial (%d) = %d\n", i, factorial (i)); i = i + 1; n = n - 1; } } else printf ("factorial of a negative number is undefined\n"); } /* factorial function computes n! for nonnegative n */ int factorial (int n) { int ans = 1; while (n > 1) { ans = ans * n; n = n - 1; } return ans; }