Skip to content

Instantly share code, notes, and snippets.

@gcs-abdulwahab
Created September 7, 2022 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcs-abdulwahab/04f395bf5a6c5b48a55ecbcdbe310f87 to your computer and use it in GitHub Desktop.
Save gcs-abdulwahab/04f395bf5a6c5b48a55ecbcdbe310f87 to your computer and use it in GitHub Desktop.
Fibonacci Code using Dynamic Programming
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
unsigned long X[100];
bool doesExist(int n){
if (X[n] != -1)
return true;
return false;
}
unsigned long fun(int n )
{
if (n == 0 || n== 1)
return n;
if ( doesExist(n) )
return X[n];
X[n] = fun(n-1) + fun(n-2) ;
return X[n];
}
int main() {
fill_n(X, 100, -1);
cout << fun(99)<<" ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment