// * ***************************************************** // * This program displays the Fibonacci sequence. * // * * // * Note: since this program utilizes 32-bit signed * // * integers, it is limited in displaying long * // * number sequences. To alleviate this, I will * // * be implementing string arithmetic. * // * ***************************************************** void main (void) { int n, next, current, previous; bool done; done = FALSE; previous = 0; current = 0; next = 0; while (!done) { printf ("%d ", next); previous = current; current = next; if (current == 0) { next = 1; } else { // // Since I'm working with signed integes, I need to stop when I hit the upper limit for a positive number. // Otherwise, the numbers will wrap around into negative numbers. if ((previous >= 0) && (current >= 0)) { next = current + previous; if (next < 0) { done = TRUE; } } else { done = TRUE; } } } printf ("\n"); }