FIBONACCI SERIES USING RECURSION - C




To write a c program to generate the Fibonacci series using recursion function.

/*FIBONACCI SERIES USING RECURSION*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
int fib(int );
clrscr();
printf("\n\n\tFIBONACCI SERIES USING RECURSION");
printf("\nEnter how many terms do you want to generate?:");
scanf("%d",&n);
printf("\nFibonacci series is as follows:\n");
for(i=1;i<=n;i++)
printf("\n\n%d",fib(i));
getch();
}
int fib(int x)
{
if((x==1)||(x==0))
return 0;
else if(x==2)
return 1;
else
return (fib(x-1)+fib(x-2));
}



OUTPUT:      

        FIBONACCI SERIES USING RECURSION
Enter how many terms do you want to generate?: 5
Fibonacci series is as follows:
0
1
1
2
3
 



Comments

Popular posts from this blog

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE

BOOKS DETAILS USING C STRUCTURE

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE