1//using dp, top -down approach memoization
2#include <iostream>
3
4using namespace std;
5int arr[1000];
6int fib(int n)
7{
8 if(arr[n]==0)
9 {
10 if(n<=1)
11 {
12 arr[n]=n;
13 }
14 else
15 {
16 arr[n]=fib(n-1)+fib(n-2);
17 }
18 }
19 return arr[n];
20}
21
22int main()
23{
24 int n;
25 cout<<"enter the value of which fibonacci value you want to calculate:"<<endl;
26 cin>>n;
27 int f=fib(n);
28 cout<<"fib value is: "<<f<<endl;
29 return 0;
30}
31