Using for

/*factorial.c - Copyright (c) 1998 Matthew Belmonte.*/ #include <stdio.h> /*an equivalent loop using 'for' instead of 'while'*/ int main(void) { register int count; int n; long factorial; printf("Compute the factorial of what number? "); scanf("%d", &n); for(factorial = 1L, count = 1; count <= n; count++) { factorial *= count; } printf("%d! = %ld\n", n, factorial); return 0; }

Back to index