Next Continued Fraction Arithmetic 25

Continued fraction objects

        struct st_cf_e {
          unsigned int n;
        };
        /*      0  1  2  3  4  5  6  7  8  9 10 11 12
           e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, 1, ...] */
        int next_term_from_e(struct st_cf_e *cf) {
          unsigned int n = cf->n;
          cf->n += 1;
          if (n == 0) return 2;
          else if (n % 3 == 2) return 2*(n/3)+2;
          else return 1;
        } 
        struct st_cf_e e;
        e.n = 0;
        while (1) {
          int next_term = next_term_from_e(&e);
          if (next_term == INFINITY) break;
          printf("%d ", next_term);
        }
        printf("\n");

Next   Back