PROGRAM TO PRINT FIBONACCI SERIES USING RECURSION

/*PROGRAM TO PRINT FIBONACCI SERIES USING RECURSION*/
#include<stdio.h>
#include<conio.h>
void fib(int,int,int);
void main()
{
int n,a=-1,b=1;
clrscr();
printf(“Enter the limit of series: “);
scanf(“%d”,&n);
printf(“First %d terms of fibonacci series are:\n”,n);
fib(a,b,n);
getch();
}
void fib(int a,int b,int n)
{
int c;
if(n>0)
{
c=a+b;
printf(“%4d”,c);
a=b;
b=c;
n=n-1;
fib(a,b,n);
}
else
return;
}

Leave a Reply

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