0% found this document useful (0 votes)
82 views

OBJECTIVE: Program To Print Fibonacci Series Using Recursion

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

OBJECTIVE: Program To Print Fibonacci Series Using Recursion

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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