Home / C / c program to print fibonacci numbers using recursion

c program to print fibonacci numbers using recursion

Fibonacci numbers using recursion

You must have already come across program to print fibonacci numbers without recursion, Here is given fbonacci number series using recursion.
PROS or New concept used:
1. You DONT have to print 0 and 1 first and run the loop n-2 times.
2. Giving modularity to program since recursion uses function or method thus decreases complexity to understand by a stranger coder.

Concept:

1. TO start with the fibonacci series we first take a=-1 and b=1
thus c= a+b = -1 +1 = 0;

11235813

a

b

c

a

b

c

a

b

c

a

b

c

2. Then replacing the values of a and b;
a=b and b=c; AS seen from above table.

ALSO CHECK:

#include<stdio.h>
void fibonacci(int a,int b,int n)
{int c;
if(n!=0)   // Thus loop will stop when n==0 BASE CASE
{
c=a+b;
printf("%d ",c);
fibonacci(b,c,--n);   //  RECURSIVE CASE
}
}
void main()
{
int n;
printf("\nHow many numbers do you want in fibonacci series : ");
scanf("%d",&n);
fibonacci(-1,1,n);
}

OUTPUT:

fibonacci series using recursion
C program for fibonacci series using recursion

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

Leave a Reply

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

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.