Fibonacci in c++ with Recursion
//Fibonacci number with Recursion
#include<iostream>
using namespace std;
int fibonacci(int n)
{
if(n==0 ||n==1 )//if n is 0,1 then return value is 1.....
{
return 1;
}
else
return fibonacci(n-1)+fibonacci(n-2);
}
int main()
{
cout<<"The value is:"<<fibonacci(5)<<endl; //call fibonacci function and pass value..
}
No comments