Ok, I initially wrote a simple code to return the Fibonacci number from the series based on the user input..
n=5 will produce 3..
static int fibonacci(in
another approach to print Fibonacci series using recursive function.
#include
// 0 1 1 2 3 5 8 13...
//
void fibb (int idx, int curr = 0, int next = 0)
{
std::cout << curr << ", ";
if(!idx) return;
if(curr == 0) {
curr = 1;
fibb(--idx, curr, next);
return;
}
next += curr;
fibb(--idx, next, curr);
}
int main()
{
fibb(10);
}