1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: /** Computes the factorial of the nonnegative integer n.
5: @pre n must be greater than or equal to 0.
6: @post None.
7: @return The factorial of n; n is unchanged. */
8: int fact(int n)
9: {
10: if (n == 0)
11: return 1;
12: else // n > 0, so n-1 >= 0. Thus, fact(n-1) returns (n-1)!
13: return n * fact(n - 1); // n * (n-1)! is n!
14: } // end fact