# Fibonacci Series between 2 numbers done recursivly

Page 1 of 1

## 0 Replies - 221 Views - Last Post: 03 March 2009 - 01:07 PM

### #1 bodom658

• Villiage Idiom

Reputation: 114
• Posts: 1,123
• Joined: 22-February 08

# Fibonacci Series between 2 numbers done recursivly

Posted 03 March 2009 - 01:07 PM

Description: just include in your program as a standard external function. I suggest only using the first two parameters of the function, the other two are defaulted and only exist to allow for recursion. If you want to use these parameters, fib1 should be the Fibonacci number below fib2, which is also a Fibonacci number.Calculates and prints Fibonacci numbers between 2 programmer defined values and prints them to the screen
```void fibbetrec(const unsigned int b1, const unsigned int b2, unsigned int fib1 = 0, unsigned int fib2 = 1);

void fibbetrec(const unsigned int b1, const unsigned int b2, unsigned int fib1, unsigned int fib2)
{
if(b1 == b2 || b1 > b2)
{
cout << "Bounds Error";
return;
}
else
{
if (fib2 >= b1 && fib2 <= b2)
cout << fib2 << endl;
int t;
t = fib2;
fib2 = fib1 + fib2;
fib1 = t;
if (fib2 <= b2)
fibbetrec(b1, b2, fib1, fib2);
else return;
}
}
```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }