Fibonacci series

countin in time

Page 1 of 1

4 Replies - 2458 Views - Last Post: 20 October 2006 - 03:14 AM Rate Topic: -----

#1 Ossidian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-October 06

Fibonacci series

Posted 17 October 2006 - 10:27 AM

I need some help modifying a fib series code so that if it reproduced once a minute you could enter a number of minutes to calculate and the out put be only that one number here is a snippet ofjust the one loop
 void fibseries()
{
	clrscr();
	
	{   
	const unsigned long limit = 4294967295;
	unsigned long next=0; //next-to-last term
	unsigned long last=1; //last term
	int time;
	cout<<"Enter how long the bacteria reproduces for (minutes):"<<endl;
	cin>>time;
	while( next < time) 
	{
	cout << last << " "; //display last term
	int sum = next + last; //add last two terms
	next = last;  //variables move forward
	last = sum;  // in the series
	}
	cout << endl;
	}
	_getch();


btw like i said i was in the middle of it soits kinda ugly and incomplete sorrry anyways heres the originalcode just to help
int main()
 {  
 const unsigned long limit = 4294967295;
 unsigned long next=0; 
 unsigned long last=1; 

 while( next < limit / 2 ) 
 {
 cout << last << " "; 
 long sum = next + last; 
 next = last;  
 last = sum;  
 }
 cout << endl;
 return 0;
 


Is This A Good Question/Topic? 0
  • +

Replies To: Fibonacci series

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Fibonacci series

Posted 17 October 2006 - 08:20 PM

a fibonacci number can be defined without the function, but based purely on n:

Attached Image

try looking this up on wikepidia for the full explanation, but it has to do with linear algebra, we solved this in my 2nd year of algebra :)

This post has been edited by William_Wilson: 17 October 2006 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

#3 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Fibonacci series

Posted 18 October 2006 - 01:05 AM

View PostWilliam_Wilson, on 17 Oct, 2006 - 08:20 PM, said:

a fibonacci number can be defined without the function, but based purely on n:

Attachment attachment

try looking this up on wikepidia for the full explanation, but it has to do with linear algebra, we solved this in my 2nd year of algebra :)


It seems to be that the number of minutes represents the term of the Fib sequence, since the fib sequence is always seeded as F(0)=1, F(1)=1, F(2) = F(0) + F(1).. etc

If i have understood the problem correctly, you need your loop to solve for F(time)...
Was This Post Helpful? 0
  • +
  • -

#4 Ossidian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-October 06

Re: Fibonacci series

Posted 18 October 2006 - 08:50 AM

Okay i now have the program printing out for the right amount of time now i just need tofigure out how to get it to print just the last number
void fibseries()
{
	clrscr();
	
	{   

	unsigned long next=0; //next-to-last term
	unsigned long last=1; //last term
	int time,i;
	cout<<"Enter how long the bacteria reproduces for (minutes):"<<endl;
	cin>>time;
	for(i = 0; i < (time); ++i) 
	{
	cout << last << " "; //display last term
	int sum = next + last; //add last two terms
	next = last;  //variables move forward
	last = sum;  // in the series
	}
	cout << endl;
	}
	_getch();
}

Was This Post Helpful? 0
  • +
  • -

#5 NyeNye  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 248
  • Joined: 24-September 06

Re: Fibonacci series

Posted 20 October 2006 - 03:14 AM

Ei how bout changing the for loop to a do while loop

Much confortable to use it on a fibo series


try look up more tutorial on this site
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1