recursive function

I am trying to write the body of a recursive function in pseudo code but it has been years since I've done any coding.
a,b,a+b,a+2b,2a+3b,3a+5b...
is the pattern. I see that this looks like a fibonacci sequence where the previous term is added to the current term to get the next term but I can't express this in any kind of code. Can anyone help me please.
The principle of recursive functions are:


function (paramter)
    if (exit condition) then return
    call function(updated parameters)


Your sequence doesn't look like a pure fibonacci - at least there are two things: a and b (and fibonacci has only one variable, that is calculated by its predecessor and prepredecessor, right?)

Anyway, fibonacci would probably look like this:
1
2
3
4
5
int fib(int x)
{
    if (x <=1) return x; // exit condition and return
    return fib(x-1) + fib(x-2);  // recursive call with updated parameter. Fibunacci is predecessor + prepredecessor.
}


But there's no 2*b or something like that involved. Good luck figuring out your sequence. :-D (I always hated these math-puzzles in my riddle-books.)

Ciao, Imi.
Topic archived. No new replies allowed.