My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

print fabonacci series using recursion

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
int main()
{
 clrscr();
 int fib(int);
 int n;
 cout<<"\nEnter the number of terms=";
 cin>>n;
 for(int i=1;i<=n;i++)
 cout<<fib(i)<<" ";
 getch();
 return 0;
 }
 int fib (int m)
 {
  if (m==1||m==2)
  return 1;
  else
  return(fib(m-1)+fib(m-2));
  }

0 comments: