Using while

/*factorial.c - Copyright (c) 1998 Matthew Belmonte.*/ #include <stdio.h> int main(void) { int n; long factorial; printf("Compute the factorial of what number? "); scanf("%d", &n); factorial = 1L; while(n > 0) { factorial *= n--; } printf("The factorial is %ld\n", factorial); return 0; }

Next slide