Question: Lately, I started to test something that's been on my mind for a while now. The Fibonacci sequence scheme has several methods to get solved, but in this instance I'm trying to do something slightly different. I'm trying to use recursion with numbers given by the user at the CLI. This is what I got so far. I'm including an iterative version that seems to work for comparison purposes. 

Numbers given by user at CLI: 4 and 6. The number **9** is the **n** here. 

Iterative:

```
1: ite: 6 
2: ite: 10
3: ite: 16
4: ite: 26
5: ite: 42
6: ite: 68
7: ite: 110
8: ite: 178
9: ite: 288

```

Recursive:

```
1: rec: 16
2: rec: 33
3: rec: 59
4: rec: 102
5: rec: 171
6: rec: 283
7: rec: 464
8: rec: 757
9: rec: 1231

```

Method for recursive version:
here **num0** and **num1** are the variables that hold the values given at CLI. 

```
public int Recursive(int n) {
    //....
        int a = num0;
        int b = num1;
        if(n < 0)
        {
          return n;
        }else{
           int c = a+b;
           a = b;
           b = c;
          return Recursive(n-1)+Recursive(n-2)+c;     
        }
    }

```

Any thoughts or ideas are greatly appreciated.

Answer: 
You can do this with the helper function. 

```
public int Recursive(int n) {
    // ....
    int a = 4;
    int b = 6;
    System.out.println(a);
    System.out.println(b);
    n--;
    return RecursiveFib(a, b, n);
}

private int RecursiveFib(int a, int b, int n) {
    if (n < 1) {
        return b;
    } else {
        System.out.println(a + b);
        int tmp = a;
        a = b;
        b += tmp;
        n--;
        return RecursiveFib(a, b, n);
    }
}

```

Since your starting numbers can be arbitrary, it is different to apply the fib(n-1) + fib(n-2) logic unless you store all your numbers.
someone else already posted the `recursive` version (without caching) so here's the `iterative`:

```
def fib_iter(n):
    a, b = 0, 1 # or: a, b = 1, 1

    i = 0
    while i < n:
        c = a + b
        a = b
        b = c

        i+=1

    return c

print fib_iter(10)

```

*EDIT*

based on the comments:

you cant start the sequence anywhere without first calculating the values and then storing them away so that in the future, you can look them up:

```
def fib(n, table):
    if n in table:
        return table[n]
    if n <= 1:
        return n

    table[n] = fib(n - 1, table) + fib(n - 2, table)

    return table[n]

cache = {}

f_goal = 1000
f = 1

while f < f_goal:
    print(fib(f, cache))
    f += 1

```