0
Damned Code
Could someone please expain to me the recursion function of fibonnaci.Yes i call it damned exercise because i lost like 15 points on the final exam
3 Answers
+ 6
Fibonacci series is : 1,1,2,3,5,8,13,...
You get the nth value by adding the last two values, and the start condition is 1 if n=1 or n=2.
+ 3
What do you want to know, you did not really ask a question.
fib(n) calculates the n-th element of the Fibonacci sequence, which itself is defined recursively/inductively exactly the way you can see in the code.
+ 1
#include <iostream>
using namespace std;
int fib(int x)
{
if(x<=2) return 1;
else
{
return fib(x-2) + fib(x-1);
}
}
int main() {
int x;
cin>>x;
cout<<fib(x);
return 0;
}