// Example 7.4. Program to print factorials for integers 0-16 #include #include using namespace std; int main() { double factorial(int n); const int MAX_INDEX = 16; cout << " Table of Factorials" << endl; cout << "Number\t\tFactorial" << endl; cout << "------\t\t---------" << endl << endl; for (int n = 0; n <= MAX_INDEX; ++n) cout << setw(4) << n << setprecision(0) << setw(19) << factorial(n) << endl; return 0; } // // Function to return the factorial of a parameter as a double // Pre: n is a nonnegative integer. // Post: n! was returned as a double. // double factorial(int n) { double fact; // n! fact = 1; // 0! = 1! = 1 for (int i = n; i > 1; --i) fact *= i; return fact; }