198k views
3 votes
The famous Fibonacci sequence, 1, 1, 2, 3, 5, 8, 13, . . . , begins with two 1s. After that, each number is the sum of the preceding two numbers. Write a program using a recursive function that requests an integer n as input and then displays the nth number of the Fibonacci sequence.

User Epodax
by
4.4k points

2 Answers

4 votes

Answer:

int recursiveFunction(int n) {

if (n == 0 || n == 1) {

return n;

}

else {

return recursiveFunction(n - 2) + recursiveFunction(n - 1);

}

Step-by-step explanation:

User Nommyravian
by
4.6k points
4 votes
Yo bro I just need help with you
User SnareHanger
by
4.6k points