Header Ads

14 - WAP to Print Fibonacci Series using Recursive Function Method in C

This Program Prints the Fibonacci Series using Recursive Function method.

//to print the Fibonacci series..
#include <stdio.h>
//Fibonacci function
void fibon ( int limit)
{
    static int sum, start = 0, second = 1;
    //checking the condition that the limit is zero or not
    if (limit != 0)
    {
        sum = start + second;
        printf ("%d\t", sum);
        start = second;
        second = sum;
        //calling the fibonacci function again
        fibon ( limit - 1 );
     }
}

//main function
int main()
{
     //declaration of variable
     int start = 0, second = 1, limit;
     //asking the user to enter the limit
     printf ("Enter the Maximum Limit (>2) : ");
     scanf ("%d", &limit);
     //printing first two numbers that is 0 and 1
     limit = limit - 2;
     printf ("%d\t %d\t", start, second);
     //calling the function
     fibon ( limit);
     //printing new line
     printf ("\n");
  return 0;
}
  
Program Output: 

No comments