diff --git a/Algorithms/dynamic_programming/fibonacci.js b/Algorithms/dynamic_programming/fibonacci.js new file mode 100644 index 000000000..0595afead --- /dev/null +++ b/Algorithms/dynamic_programming/fibonacci.js @@ -0,0 +1,14 @@ + +function fib(n) { + var table = []; + table.push(1); + table.push(1); + for (var i = 2; i < n; ++i) { + table.push(table[i - 1] + table[i - 2]); + } + console.log("The %dth fibonacci number is %d", n, table[n - 1]); +} + +fib(200); +fib(5); +fib(10);