/* * factorial.c * Douglas L. Jones * University of Illinois at Urbana-Champaign * August 28, 2012 * * (c) 2012 by Douglas L. Jones * This work is made available according to the Creative Commons "Attribution" license * http://creativecommons.org/licenses/by/3.0/ * * factorial.c: Computes the factorial of a positive integer * * Developer notes: * * User notes: * */ #include /* Declare constants */ #define START_COUNT 2 int main() { /* Declare variables */ int counter; /* holds the current index in the factorial loop */ int product; /* holds the accumulating factorial product */ int endCount; /* holds the value of which to compute the factorial */ /* Read in value of which to compute factorial */ printf("This program will compute N!; enter N: "); scanf("%d", &endCount); printf("\n"); /* Compute the factorial */ product = 1; for (counter = START_COUNT; counter <= endCount; counter = counter + 1) { product = counter*product; } /* Add patch for input = 0 ! */ /* Print the answer */ printf("%d\n", product); return 0; }