// Fibonacci.cmm  CMM code to print fibonacci numbers until the user presses a key


flush_keyboard() { while kbhit() getch() }

/******************************************************************************/
/***********************  ARRAY FIBONACCI METHOD  *****************************/
/******************************************************************************/
printf("Printing Fibonacci sequence while creating an array until you press a key,\n")
printf("or until we run out of memory or stack space.\n")
for ( i = 0; !kbhit(); i++ )
   printf("%d\t",FibArray[i] = (i < 2) ? i + 1 : FibArray[i-1] + FibArray[i-2])

flush_keyboard()

/******************************************************************************/
/*********************  RECURSIVE FIBONACCI METHOD  ***************************/
/******************************************************************************/
printf("\nPrinting Fibonacci sequence through recursion until you press a key,\n")
printf("or until we run out of memory or stack space.\n")
for ( i = 1; !kbhit(); i++ )
   printf("%d\t",fib(i))

flush_keyboard()

fib(n)   // return any number from fibonacci seqeunce, evaluating previous values
{        // recursively if necessary
   return (n <= 2) ? n : fib(n-1) + fib(n-2)
}