eris2010

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

fibonacci.c (659B)


      1 /*
      2  * Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free
      3  * software under the GNU GPL v3 license or any later version. See
      4  * COPYING in the root directory for details.
      5  */
      6 
      7 #include <conio.h>
      8 #include <limits.h>
      9 
     10 void fibonacci(unsigned long a, unsigned long b) {
     11   unsigned long r = a + b;
     12   static const unsigned long max_param = ULONG_MAX/2;
     13   cprintf("%lu\r\n", r);
     14   if (r  < max_param)
     15       fibonacci(b, r);
     16 }
     17 
     18 void main(void){
     19   for(;;) {
     20     cprintf("0\r\n");
     21     cprintf("1\r\n");
     22     fibonacci(0, 1);
     23     if (kbhit()) {
     24       // Key has been pressed.
     25       // Exit if it is 'q'
     26       if (cgetc() == 'q') {
     27 	break;
     28       }
     29     }
     30   }
     31 }