11.10 LAB: Fibonacci sequence (recursion).
C++ Please
11.10 LAB: Fibonacci sequence (recursion)
The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, for example: 0, 1, 1, 2, 3, 5, 8, 13. Complete the Fibonacci function, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1.
Ex: If the input is:
7
the output is:
Fibonacci(7) is 13
Note: Use recursion and Do Not use any loops.
LAB ACTIVITY
11.10.1: LAB: Fibonacci sequence (recursion)
0/10
main.cpp
Load default template..
1 #include <iostream>
2 using namespace std;
3
4 int Fibonacci(int n) {
5
6 /*Type your code here.*/
7
8 }
9
10 int main() {
11 int startNum;
12
13 cin >> startNum;
14 cout << "Fibonacci(" << startNum << ") is " << Fibonacci(startNum) << endl;
15
16 return 0;
17 }
18