Answers for "fibonaci 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

fibanachi

function fib(n){
	var fib = [0, 1];
	var i = 0;
	for (let i = 0; i != n-2; i++){

		fib.push(fib[i]+fib[i+1]);

	}

	return fib;

}
Posted by: Guest on January-04-2021
-1

fibonacci numbers

f(n) = f(n-1) + f(n-2) 
                                  f(6)
                                   ^
  			                       /\
                f(5)               +                       f(4)
                ^
               /\                                           /\
                
        f(4)    +           f(3)                     f(3)    +    f(2)
       ^                       ^                     ^              ^
      /\                       /\                    /\            /\
   
 f(3)   +       f(2)            f(2) +f(1)       f(2) + f(1)   f(1) +  f(0)             
   ^              ^                ^                ^
   /\             /\                /\              /\
    
f(2) + f(1)      f(1) +  f(0)     f(1)+ f(0)       f(1) + f(0)         
  ^
  /\
f(1) +  f(0) 
  
//f(6) = 8   ==>  f(1)*8    f(1) appears 8 times 
 double feb  = (1/Math.pow(5,0.5)) * (Math.pow((1+Math.pow(5,0.5))/2,n)) - (1/Math.pow(5,0.5))* (Math.pow((1-Math.pow(5,0.5))/2,n));  
  
f(1) == 1;
Posted by: Guest on August-01-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
0

fibanachi

function fib(n){
	var fib = [0, 1];
	var i = 0;
	for (let i = 0; i != n-2; i++){

		fib.push(fib[i]+fib[i+1]);

	}

	return fib;

}
Posted by: Guest on January-04-2021
-1

fibonacci numbers

f(n) = f(n-1) + f(n-2) 
                                  f(6)
                                   ^
  			                       /\
                f(5)               +                       f(4)
                ^
               /\                                           /\
                
        f(4)    +           f(3)                     f(3)    +    f(2)
       ^                       ^                     ^              ^
      /\                       /\                    /\            /\
   
 f(3)   +       f(2)            f(2) +f(1)       f(2) + f(1)   f(1) +  f(0)             
   ^              ^                ^                ^
   /\             /\                /\              /\
    
f(2) + f(1)      f(1) +  f(0)     f(1)+ f(0)       f(1) + f(0)         
  ^
  /\
f(1) +  f(0) 
  
//f(6) = 8   ==>  f(1)*8    f(1) appears 8 times 
 double feb  = (1/Math.pow(5,0.5)) * (Math.pow((1+Math.pow(5,0.5))/2,n)) - (1/Math.pow(5,0.5))* (Math.pow((1-Math.pow(5,0.5))/2,n));  
  
f(1) == 1;
Posted by: Guest on August-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language