FIBONACCI SERIES USING RECURSION
#include “conio.h”
#include”stdio.h”
int fib(int,int,int);
void main()
{
int a=0,b=1,n;
clrscr();
printf("\nEnter the limit : ");
scanf("%d",&n);
printf("\nThe Fibonacci Series of %d numbers :",n);
fib(a,b,n);
getch();
}
int fib(int a,int b,int n)
{
int c;
if(n==0)
return(1);
else
{
printf(" %d",a);
c=a+b;
b=a;
a=c;
}
n--;
return(fib(a,b,n));
}
Output will be
Enter the limit : 10
The Fibonacci Series of 8 numbers : 0 1 1 2 3 5 8 13 21 34
No comments:
Post a Comment