//------------------------------------------------------------------- // uselib.cpp // // This program shows how a C++ application can use our Shared // Library of C functions (named 'libcomb.so') if we assume it // is located in our current working directory: // // compile using: $ g++ uselib.cpp -o uselib -L. -lcomb -Wl,-rpath,. // // Alternatively, a user with suitable privileges can move the // shared object file 'libcomb.so' to the system sub-directory // '/usr/local/lib' and then recompile this application using: // // $ g++ uselib.cpp -o uselib -L. -lcomb -Wl,-rpath,/usr/local/lib // // programmer: ALLAN CRUSE // written on: 14 MAY 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() extern "C" unsigned int comb( int n, int m ); extern "C" unsigned int fibonacci( unsigned int n ); extern "C" unsigned int factorial( unsigned int n ); int main( int argc, char **argv ) { int i, r, k; // print a list of factorial values printf( "\n\nSome factorial values: \n\n" ); for (i = 0; i < 10; i++) printf( " %d ", factorial( i ) ); printf( "\n" ); // print a list of fibonacci values printf( "\n\nSome fibonacci values: \n\n" ); for (i = 0; i < 10; i++) printf( " %d ", fibonacci( i ) ); printf( "\n" ); // print some rows of Pascal's Triangle printf( "\n\nSome rows of the Pascal Triangle: \n" ); for (r = 0; r < 10; r++) { printf( "\n" ); for (k = 0; k <= r; k++) printf( "%5d ", comb( r, k ) ); } printf( "\n" ); printf( "\n\n" ); }