C++ Programming Blog

 
 
 

Image

 # include <iostream.h>
 # include    <conio.h>


 long fibonacci(long);
 long factorial(long);

 int main( )
    {
       clrscr( );

       cout<<\"\\n The first five elements of the fibonacci series are : \";

       for(int count_1=0;count_1<5;count_1++)
      cout<<fibonacci(count_1)<<\" \";

       cout<<\"\\n\\n The factorial first five elements of the fibonacci series are : \";

       for(int count_2=0;count_2<5;count_2++)
      cout<<factorial(fibonacci(count_2))<<\" \";

       getch( );
       return 0;
    }



 //------------------------  Function Definitions  -----------------------//




 //--------------------------  fibonacci(long)  --------------------------//


 long fibonacci(long number)
    {
       if(number==0 || number==1)
      return number;

       else
      return fibonacci(number-1)+fibonacci(number-2);
    }


 //--------------------------  factorial(long)  --------------------------//


 long factorial(long number)
    {
       int count=1;
       int factorial=1;

       if(number==0)
      factorial=1;

       else
      {
         do
        {
           factorial=factorial*count;
           count++;
        }
         while(count<=number);
      }

       return factorial;
    }

 
 
Didn't find what you were looking for? Find more on Program to print the factorial of first five elements of the fibonacci series