C Programming Tutorial

 
 
 
 
#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

 
 
Didn't find what you were looking for? Find more on Recursive program to generate fibonacci Series