Здравейте, някой може ли да ми открие грешката в моето решение.
Each member of the Fibonacci sequence is calculated from the sum of the two previous members. The first two elements are 1, 1. Therefore the sequence goes as 1, 1, 2, 3, 5, 8, 13, 21, 34…
The following sequence can be generated with an array, but that’s easy, so your task is to implement it recursively.
If the function getFibonacci(n) returns the nth Fibonacci number, we can express it using getFibonacci(n) = getFibonacci(n-1) + getFibonacci(n-2).
However, this will never end and in a few seconds a Stack Overflow Exception is thrown. In order for the recursion to stop it has to have a "bottom". The bottom of the recursion is getFibonacci(1), and should return 1. The same goes for getFibonacci(0).
- On the only line in the input the user should enter the wanted Fibonacci number N where 1 ≤ N ≤ 49
The output should be the nth Fibonacci number counting from
Линк към задача: Stacks and Queues - Exercises - SoftUni Judge
Мое решение: https://pastebin.com/q16Y2zku -- 88/100 гърми тест 1
Благодаря за отделеното време!