Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Recursive program to generate fibonacci Series

Posted By: Volker Fischer     Category: C Programming     Views: 5557

Write a recursive program to generate fibonacci Series.

Code for Recursive program to generate fibonacci Series in C Programming

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "valid.c"void generateFibonacci(int nterm);
   int nterm = 0;
   int preval = 1;
   int curval = 0;
   int sum = 0;
   int count = 1;

void main()
{  clrscr();
   getPosInteger("Enter the number up to which you want to generate the fibonacci series : ", &nterm);
   generateFibonacci(nterm);
   getch();
}

   void generateFibonacci(int nterm)
   {

    sum = curval + preval;
    count++;
    if(count > nterm)
      exit(0);
    printf("%d ", sum);
    preval = curval;
    curval = sum;
    generateFibonacci(nterm);
   }

    /****************   Input ******************/
Enter the number up to which you want to generate the fibonacci series : 5 /**************** Output ******************/
1 1 2 3 5 8
  
Share: 


Didn't find what you were looking for? Find more on Recursive program to generate fibonacci Series Or get search suggestion and latest updates.

Volker Fischer
Volker Fischer author of Recursive program to generate fibonacci Series is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!