//------------------------------------------------------------------- // hyperfib.cpp // // This program computes and displays the first fifteen numbers // in a recursively-defined sequence that is based on extending // the usual 'two-level' rule for the famous Fibonaci Sequence. // // programmer: ALLAN CRUSE // written on: 14 MAY 2008 //------------------------------------------------------------------- #include // for printf(), perror() #define N 15 // the number of terms to display int hyperfib( unsigned int n ) { if ( n < 3 ) return n; else return hyperfib( n-1 ) + hyperfib( n-2 ) + hyperfib( n-3 ); } int main( int argc, char **argv ) { printf( "\nOur hyper-fibonacci number-sequence is shown below: \n\n" ); for (int n = 0; n < N; n++) printf( "%5d", hyperfib( n ) ); printf( "\n\n" ); }