Home Forums C Programming program for fibonacci series

Viewing 2 reply threads
  • Author
    Posts
    • #2140
      bajean
      Participant

      frienz plz help me in making a progarm for fibonacci series by recursion method……
      this is the pattern for fibonaci series:
      0 1 1 2 3 5 8 13 21 34 55……and so on…

      remember u have to code by recursion method…..

    • #3456
      Humayan
      Participant

      try:
       

      /****************************************************************
      * File Name : c:programshelpfibonacci1.cpp
      * Date : September,11,2008
      * Comments : new project
      * Compiler/Assembler :
      * Program Shell Generated At: 3:40:46 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

      #include < stdio.h >
      //#include < string.h >
      //#include < conio.h >
      //#include < math.h >
      //#include < iomanip >
      //#include < ctype.h >
       

      //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
       void fibonacci ( int firstTerm , int secondTerm , int numberOfTerms );
      //##################################################################################

       //main function ******************************
      int main ( )
      {
          int numberOfTerms;
          printf ( "enter the number of terms: " );
          scanf ( "%i" , & numberOfTerms );
          fibonacci ( 0 , 1 , numberOfTerms );
       printf ( "n" );
       return 0 ;
      }

      /******************************* FUNCTION DEFINITION ******************************
       Name : fibonacci
       Parameters :
        firstTerm a(n) int ,
        secondTerm a(n) int ,
        numberOfTerms a(n) int

       Returns: Void type
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      void fibonacci ( int firstTerm , int secondTerm , int numberOfTerms )
      {
          if ( numberOfTerms == 0 )
          {
              return;
          }
          else
          {
              if ( firstTerm == 0 )
        {
         printf ( "0 1 " );
         numberOfTerms -= 2;
        }
        printf ( "%i" , firstTerm + secondTerm );
              printf ( " " );
        fibonacci ( secondTerm , firstTerm + secondTerm , numberOfTerms - 1 );
          }
          return;
      }
       
    • #3457
      berhane
      Participant
      #include
      void printfab(int,int,int);
      void main()
      {
       int i=0,j=1,n;
        printf("nEnter last limit ");
        scanf("%d",&n);
        printf("%d  %d ",i,j);
        printfab(i,j,n)
      }
      void printfab(int i,int j,int d)
      {
       
        int temp;
        while(temp   { 
          temp=i+j;
          j=temp;
          i=j;
          printf('n %d",temp);
          printfab(i,j,d);
        } 
       
Viewing 2 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.