diff --git a/code/unclassified/src/optimized_fibonacci/optimized_fibonacci.cpp b/code/unclassified/src/optimized_fibonacci/optimized_fibonacci.cpp index 8d99567a6e..80166c5cf1 100644 --- a/code/unclassified/src/optimized_fibonacci/optimized_fibonacci.cpp +++ b/code/unclassified/src/optimized_fibonacci/optimized_fibonacci.cpp @@ -3,12 +3,12 @@ long long fibonacci (int n) { static long long fib[100] = {}; // initialises the array with all elements as 0 - fib[1] = 0; + fib[1] = 0; fib[2] = 1; - - if (n == 1 || n == 2) + + if (n == 1 || n == 2) return fib[n]; - else if (fib[n] != 0) + else if (fib[n] != 0) return fib[n]; else { fib[n] = fibonacci (n - 1) + fibonacci (n - 2); @@ -17,12 +17,9 @@ long long fibonacci (int n) { } int main () { - int n; std::cout << "Enter number of terms: "; std::cin >> n; - for (int i = 1; i <= n; i++) - std::cout << fibonacci (i) << std::endl; - - return 0; + for (int i = 1; i <= n; i++) + std::cout << fibonacci (i) << std::endl; }