Generate Fibonacci series using recursion

Q. Write a C program to generate Fibonacci series using recursion method.
or
Q. Write a C program to accept any number from user and create its equal-ant Fibonacci series using recursion method.

Ans.

/*c program to generate Fibonacci series using recursion method*/
#include<stdio.h>
#include<conio.h>
int fibo(int , int ); /*declaration function*/
int main()
{
 int num=1,previous_num=0;
 printf("Fibonacci Series first 30 elements: ");
 printf("\n\n\t1");
 fibo(previous_num,num); /*calling function*/
 getch();
 return 0;
}

fibo(int prev, int n) /*definition of function*/
{
 static int r=1;
 int series;
 if(r!=30)
 {
   series=prev+n;
   prev=n;
   n=series;
   printf("\n\t%d",series);
   r++;
   fibo(prev,n);
 }
}

/************Output************/


Output of generate Fibonacci series to specific number using recursion method C program
Figure: Screen shot for Generate Fibonacci series to a 
specific range using recursion method C program



Related Programs:
  1. Fibonacci series C program
  2. Flowchart for Fibonacci series
  3. Search a number is Fibonacci term or not

Comments