# Thread: Fibonacci Sequence

1. ## Fibonacci Sequence

I'm new to c++ programming! I need some help writing a program that generates then prints out the terms of the fibonacci sequence. Any suggestions?

2. Tech youreslff C++ in 21 days have a couple of differnt solutions.

http://firstpod.tripod.com/cpp21/

~Barjor

3. Any number in the Fibonacci Sequence is equal to the sum of the two previous numbers. You start with 0 and 1.

Code:
```0       = 0
1       = 1
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
3 + 2 = 5
5 + 3 = 8
8 + 5 = 13
etc...```
I'm SURE you can figure it out from there!!!

4. Try a recursive function, that's how it's done in the Deitel textbook. The numbers get large pretty quickly, though.

5. ## Here's a hint...

try this (easier said than done):

a[n] += a[n-1] + a[n-2]

6. Try this code:

#include <stdio.h>

void main(void)
{
char get_key;
int x = 1;
int y;
int z;
/* just make a loop for the rest of the code to limit how high it counts in fibonacci numbers. A for( ; ; loop may be best. */

printf("%f", x);
z = x + y;
x = z;

7. ## Sorry - pressed send key to early.

Sorry, pressed the send key accidentally. Just make the following changes to the code:

After you have the printf statement, add, "y = x" on the next line. At the end, add, "getch(get_key);", and on the final line, "}".
That should, work, but double check some of variable assignements and math.

Popular pages Recent additions