Created
September 7, 2022 10:00
-
-
Save gcs-abdulwahab/04f395bf5a6c5b48a55ecbcdbe310f87 to your computer and use it in GitHub Desktop.
Fibonacci Code using Dynamic Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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