//----------------------------------------------------------------- // tryrecur.cpp // // Here is an example of mixed-language programming in which // the external assembly language procedure that gets called // has been implemented using recursion (i.e., that function // will call itself). We retained the code for a high-level // implementation of that function, but we commented it out. // // compile-and-link: $ g++ tryrecur.cpp fact.o -o tryrecur // and execute with: $ ./tryrecur // // programmer: ALLAN CRUSE // written on: 18 MAR 2007 //----------------------------------------------------------------- #include // for the 'printf()' function-prototype #define N_MAX 10 // the maximum function-argument allowed const char header[] = "\n n n! \n"; // asciz string const char border[] = "------------------\n"; // asciz string extern "C" int factorial( int n ); /* { if ( n == 0 ) return 1; else return n * factorial( n-1 ); } */ int main( void ) { printf( "%s", header ); printf( "%s", border ); for (int n = 0; n <= N_MAX; n++) { int f = factorial( n ); printf( " %2d %-10d \n", n, f ); } printf( "%s", border ); }