# Fibonacci series

Page 1 of 1

## 4 Replies - 2870 Views - Last Post: 20 October 2006 - 03:14 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=19768&amp;s=fa9c21942a3895672c291df44c18319c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Ossidian

• New D.I.C Head

Reputation: 0
• 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

• lost in compilation

Reputation: 207
• Posts: 4,812
• 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:

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

### #3 gregoryH

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

## Re: Fibonacci series

Posted 18 October 2006 - 01:05 AM

William_Wilson, on 17 Oct, 2006 - 08:20 PM, said:

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

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)...

### #4 Ossidian

• New D.I.C Head

Reputation: 0
• 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();
}
```

### #5 NyeNye

Reputation: 1
• 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