///////////////////////////////////////////////////// // // assertions.cpp // // Jeff Ondich, 4/7/04 // // A simple example of the use of an assertion to // verify a precondition. // ///////////////////////////////////////////////////// #include #include using namespace std; int factorial( int n ); int main() { int n = 0; cout << "Number, please: "; cin >> n; cout << n << "! = " << factorial( n ) << endl; return 0; } // Returns the factorial of the specified integer. // Precondition: n >= 0 and n < 13. int factorial( int n ) { assert( n >= 0 && n < 13 ); if( n == 0 ) return 1; return n * factorial( n - 1 ); }