Created
December 15, 2015 13:15
-
-
Save Nata01/297c7a4424cad91f1098 to your computer and use it in GitHub Desktop.
Fibonacci numbers. Solution via array.
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
int fib(int nElem){ | |
int *arr = new int[nElem+1]; | |
arr[0] = 0; | |
arr[1] = 1; | |
for(int i = 2; i <= nElem; i++){ | |
arr[i] = arr[i-1] + arr[i-2]; | |
} | |
return arr[nElem]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment