eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | README | LICENSE

fibonacci.c (472B)


      1 #include <conio.h>
      2 #include <limits.h>
      3 
      4 void fibonacci(unsigned long a, unsigned long b) {
      5   unsigned long r = a + b;
      6   static const unsigned long max_param = ULONG_MAX/2;
      7   cprintf("%lu\r\n", r);
      8   if (r  < max_param)
      9       fibonacci(b, r);
     10 }
     11 
     12 void main(void){
     13   for(;;) {
     14     cprintf("0\r\n");
     15     cprintf("1\r\n");
     16     fibonacci(0, 1);
     17     if (kbhit()) {
     18       // Key has been pressed.
     19       // Exit if it is 'q'
     20       if (cgetc() == 'q') {
     21 	break;
     22       }
     23     }
     24   }
     25 }