fibbonaci numbers code example
Example 1: fibonacci numbers
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Example 2: fibbonaci numbers
//using dp, top -down approach memoization
#include <iostream>
using namespace std;
int arr[1000];
int fib(int n)
{
if(arr[n]==0)
{
if(n<=1)
{
arr[n]=n;
}
else
{
arr[n]=fib(n-1)+fib(n-2);
}
}
return arr[n];
}
int main()
{
int n;
cout<<"enter the value of which fibonacci value you want to calculate:"<<endl;
cin>>n;
int f=fib(n);
cout<<"fib value is: "<<f<<endl;
return 0;
}