0 1 1 2 3 5 8 13 21 34 55 ...

__Fibonacci Sequence, C++ implementation__

int Fibonacci(int n)

{

if (n == 0)

{

return 0;

}

if (n == 1 || n == 2)

{

return 1;

}

return Fibonacci(n - 1) + Fibonacci(n - 2);

}

NOTE: In the above implementation it returns zero if n is equal to zero and return 1 if n is less than or equal to 2. Those are the base cases which cause the recursion to stop.

## No comments:

## Post a Comment