+ Reply to Thread
Results 1 to 2 of 2

Thread: Fibonacci number

  1. #1
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321

    Fibonacci number

    Write recurssive fibonacci and print the value in order (eg 0 1 1 2 3 5)

  2. #2
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321
    Code:
    #include <iostream>
    
    using namespace std;
    
    // Recursive Method.......
     
    int fibo_gen(int,int,int);
     
    void main()
     
    {
     
    	int initial_value=0,final_value=1,count=50;
    	fibo_gen(initial_value,final_value,count);
    }
     
    int fibo_gen(int initial_value,int final_value,int count)
     
    {
    	int temp;
    	 
    	if (count>0)
    	{
    		cout<<initial_value<<" ";
    		temp=initial_value+final_value;
    		initial_value=final_value;
    		final_value=temp;
    		count=count-1;
    		fibo_gen(initial_value, final_value, count); 
    	}
    	 
    	else
    		return(0);
    }

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts