Programming with Passion

Make the best out of everything.

Monday, 10 October 2016

nth number of a Fibonacci Series

Program to find the nth number of a Fibonacci Series Using RECURSION.

int fibo(int n)
{
if(n==1)
return 0;
else if (n==2)
return 1;
else return fibo(n-2)+fibo(n-1);
}
void main()
{
int m,f;
cin>>m;
f=fibo(m);
cout<<m;
if(m==1)cout<<"st";
else if (m==2)cout<<"nd";
else if (m==3)cout<<"rd";
else cout<<"th";
cout<<"  element of the Fibonacci series is  "<<f;
getch();
}
Happy coding.

No comments:

Post a Comment