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?

Printable View

- 09-07-2001UnregisteredFibonacci 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?

- 09-07-2001Barjor
Tech youreslff C++ in 21 days have a couple of differnt solutions.

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

~Barjor - 09-07-2001TerranFury
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...

- 09-07-2001Brown Drake
Try a recursive function, that's how it's done in the Deitel textbook. The numbers get large pretty quickly, though.

- 09-07-2001valar_kingHere's a hint...
try this (easier said than done):

a[n] += a[n-1] + a[n-2] - 09-08-2001Sean
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; - 09-08-2001SeanSorry - 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.