Home Forums C Programming program for fibonacci series Reply To: program for fibonacci series

#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;
}