This can be done with both iteration and recursion.
Solution #1: Here is an implementation using recursion,
Solution #1: Here is an implementation using recursion,
int fib_rec(int n)
{
if(n == 0)
return 0;
if((n == 1) || (n == 2))
return 1;
return fib_rec(n-1) + fib_rec(n-2);
}
No comments:
Post a Comment