Write a program to find the nth term in the Fibonacci series using recursion. Note that the first 2 terms in the Fibonacci Series are 0 and 1.
Answers
Answered by
0
Answer:
Explanation:
using namespace std;
int fib(int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main ()
{
int n = 9;
cout << fib(n);
getchar();
return 0;
}
Answered by
2
Answer:
#include<iostream>
using namespace std;
int fib (int);
int main ()
{
int n, result;
cin>>n;
result = fib (n - 1);
cout<<"The term "<<n<<" in the fibonacci series is "<<result;
return 0;
}
int fib (int n)
{
if (n == 0)
{
return 0;
}
else if (n == 1)
{
return 1;
}
else
{
return (fib (n - 1) + fib (n - 2));
}
}
Explanation:
Similar questions