fibbonaci c 2b 2b

Solutions on MaxInterview for fibbonaci c 2b 2b by the best coders in the world

showing results for - "fibbonaci c 2b 2b"
Veronica
15 Apr 2017
1//dp ;Bottom up approach
2#include <iostream>
3
4using namespace std;
5int fib(int n)
6{
7    int fib[n+1];
8    fib[0]=0;
9    fib[1]=1;
10    for(int i=2;i<=n;i++)
11    {
12        fib[i]=fib[i-1]+fib[i-2];
13    }
14    return fib[n];
15}
16
17int main()
18{
19    int n;
20    cout<<"enter the value whose fibonaaci value you want to claculate:"<<endl;
21    cin>>n;
22    if(n<=1)
23    {
24        cout<<"fib is: "<<n<<endl;
25    }
26    else
27    {
28        cout<<"fib is: "<<fib(n)<<endl;
29    }
30    return 0;
31}
32