Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find nth fibonacci number

// a dynamic programming approach for generating any number of fibonacci number
#include<bits/stdc++.h>
using namespace std;
 
long long int save[100]; // declare any sized array
long long int fibo(int n){
  if(n==0) return 0;
  if(n==1) return 1;
  if(save[n]!=-1) return save[n]; //if save[n] holds any value that means we have already calculated it and can return it to recursion tree
  save[n]=fibo(n-1)+fibo(n-2); // if it come tp this line that means I don't know what is the value of it
  return save[n];
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset(save,-1,sizeof save);
  cout<<fibo(2)<<'
';

  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Python :: How to check if variable exists in a column 
Python :: Python Tkinter Label Widget Syntax 
Python :: Python Tkinter SpinBox Widget Syntax 
Python :: all python 
Python :: login() takes 1 positional argument but 2 were given 
Python :: intersection_update() Function of sets in python 
Python :: python equivalent linkedhashmap 
Python :: python Write a program to reverse an array or string 
Python :: saving to PIL image to s3 
Python :: how to get the string between brackets in a string in python 
Python :: Mirror Inverse Program in python 
Python :: Instance Method With Property In Python 
Python :: convert set to list python time complexity method 1 
Python :: how to open cmd as administrator with python 
Python :: python how to not allow class instance 
Python :: make max function returning more than one value python 
Python :: Power Without BuiltIn Function 
Python :: how to append the items in list 
Python :: python iterate through lists itertools 
Python :: Dizideki en son elemani alma 
Python :: selenium restart browser python 
Python :: linux echo redirect output to python script 
Python :: integrate label into listbox tkinter 
Python :: how to create a cubic function in python 3 
Python :: can 2020 get any worse 
Python :: dataframeclient influxdb example 
Python :: print("python is good") 
Python :: Improve the Request Add Timeout to request 
Python :: admin email errors 
Python :: Pandas index column title or name 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =