0% found this document useful (0 votes)
62 views5 pages

Fibonacci Series Using Recursion in C++

The program uses recursion to print a Fibonacci series of user-defined length. It defines a fibonacci function that returns either n or the sum of the previous two Fibonacci numbers. The main function gets user input n, initializes a counter i, and calls the fibonacci function in a while loop, printing each term until i equals n.

Uploaded by

Manvinder Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views5 pages

Fibonacci Series Using Recursion in C++

The program uses recursion to print a Fibonacci series of user-defined length. It defines a fibonacci function that returns either n or the sum of the previous two Fibonacci numbers. The main function gets user input n, initializes a counter i, and calls the fibonacci function in a while loop, printing each term until i equals n.

Uploaded by

Manvinder Kaur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OBJECTIVE: Program to print Fibonacci series using recursion

#include<iostream.h>
#include<conio.h>
int fibonacci (int n)
{
if (n==1||n==0)
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
clrscr();
int n,i=0;
cout<<"enter the length of fibonaci series";
cin>>n;
cout<<"\nyour series is" ;
while (i<n)
{
cout<<" "<<fibonacci (i);
i++;
}
return 0;
}
OUTPUT
OBJECTIVE: Program to print Fibonacci series using recursion
#include<iostream.h>
#include<conio.h>
int fibonacci (int n)
{
if (n==1||n==0)
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
clrscr();
int n,i=0;
cout<<"enter the length of fibonaci series";
cin>>n;
cout<<"\nyour series is" ;
while (i<n)
{
cout<<" "<<fibonacci (i);
i++;
}
return 0;
}

OUTPUT
OBJECTIVE: Program to print Fibonacci series using recursion
#include<iostream.h>
#include<conio.h>
int fibonacci (int n)
{
if (n==1||n==0)
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
clrscr();
int n,i=0;
cout<<"enter the length of fibonaci series";
cin>>n;
cout<<"\nyour series is" ;
while (i<n)
{
cout<<" "<<fibonacci (i);
i++;
}
return 0;
}

OUTPUT
OBJECTIVE: Program to print Fibonacci series using recursion
#include<iostream.h>
#include<conio.h>
int fibonacci (int n)
{
if (n==1||n==0)
{
return(n);
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
int main()
{
clrscr();
int n,i=0;
cout<<"enter the length of fibonaci series";
cin>>n;
cout<<"\nyour series is" ;
while (i<n)
{
cout<<" "<<fibonacci (i);
i++;
}
return 0;
}
OUTPUT

You might also like