/////// File fac.C /////// // factorial function computes n! for non-negative n /* version 1 */ #include int factorial(int n) { int ans = 1; while (n > 1) { ans = ans * n; n = n - 1; } return(ans); } int main() { cout << "Please enter n :"; int n; // declaration cin >> n; // input from keyboard if ( n >= 0 ) cout << "factorial(" << n << ")=" << factorial(n) << "\n"; else cerr << "Undefined: factorial of a negative number\n"; return(0); }