Program Code
//Find Fibonacci Series Using Recursion in C Programming #include"stdio.h" #include"conio.h" fibonacci(int n); void main() { int n,r,i; clrscr(); printf("********** Fibonacci Series Using Recursion *********\n"); printf("enter a number: "); scanf("%d",&n); printf("\n\n"); for(i=0;i<=n;i++) { r=fibonacci(i); printf("\t%d",r); } getch(); } fibonacci(int n) { int f; if((n==1)||(n==2)) return(1); else if(n==0) return(0); else f=fibonacci(n-2)+fibonacci(n-1); return(f); }Output
1 comment:
//Another simple program tintumon18@gmail.com
#include
#include
void fib(int n,int f1=0,int f2=1)
{
if(n)
{
printf(“%d “,f1);
fib(n-1,f2,f1+f2);
}
else return;
}
void main()
{
int n;
printf(“\n\tEnter the number\n”);
scanf(“%d”,&n);
printf(“\n\tThe Fibonacci series using recursion is\n\t”);
fib(n);
getch();
}
Post a Comment
Dont SPAM