Fibonaccie series using Recursion function In c++

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

/* Program to print Fibonaccie series

using Recursion function*/

# include<iostream.h>
#include<conio.h>
int fib(int n);
void main()
{
clrscr();
int n,i;
cout<<“Enter the no. of terms\n”;
cin>>n;
cout<<“Fibonacci Series”;
for(i=1;i<=n;i++)
cout<<” “<<fib(i);
getch();
}

int fib(int n)
{
int x,y;
if(n<=1)
return(n);
x=fib(n-1);
y=fib(n-2);
return(x+y);
}

——————–OUTPUT—————————-
Enter the no. of terms
10
Fibonacci Series 1 1 2 3 5 8 13 21 34 55

Leave a Reply

Your email address will not be published. Required fields are marked *