fibonacci numbers
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
fibonacci numbers
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us