Write a cpp program to print fibonacci series?

#include<iostream.h>
#include<conio.h>
int fib(int n)
{
 if(n==1||n==2)
  return(1);
 else
  return(fib(n-1)+fib(n-2));
}
int main()
{
 int i,n;
 clrscr();
 cout<<"Enter any number: ";
 cin>>n;
 cout<<"Fibonacci series:";
 for(i=1;i<=n;i++)
  cout<<fib(i)<<" ";
 getch();
}

Ourput:

Comments

Popular posts from this blog

Larch Soft Pvt. Ltd. - Best Website & Hosting Provider