Answers for "fibonic numbers"

0

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;
}
Posted by: Guest on May-28-2021
0

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;
}
Posted by: Guest on May-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language