mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-11-05 23:28:34 +08:00
fix: Remove repeated algorithm (#1067)
* Improve code and add support for 46+ fibb numbers * Docs: Fibbonacci docs added * fix: Add c++ suggested code * fix: remove repeated algorithm
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
int arr[1000000];
|
|
||||||
int fib(int n) {
|
|
||||||
if (arr[n] == -1) {
|
|
||||||
if (n <= 1)
|
|
||||||
arr[n] = n;
|
|
||||||
else
|
|
||||||
arr[n] = fib(n - 1) + fib(n - 2);
|
|
||||||
}
|
|
||||||
return arr[n];
|
|
||||||
}
|
|
||||||
int main(int argc, char const *argv[]) {
|
|
||||||
int n;
|
|
||||||
cout << "Enter n: ";
|
|
||||||
cin >> n;
|
|
||||||
for (int i = 0; i < n + 1; ++i) {
|
|
||||||
arr[i] = -1;
|
|
||||||
}
|
|
||||||
cout << "Fibonacci number is " << fib(n) << endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user