Fibonacci Sequence

This is a discussion on Fibonacci Sequence within the C++ Programming forums, part of the General Programming Boards category; I'm new to c++ programming! I need some help writing a program that generates then prints out the terms of ...

  1. #1
    Unregistered
    Guest

    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. #2
    Barjor
    Guest
    Tech youreslff C++ in 21 days have a couple of differnt solutions.

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

    ~Barjor

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    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. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Try a recursive function, that's how it's done in the Deitel textbook. The numbers get large pretty quickly, though.

  5. #5
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288

    Post Here's a hint...

    try this (easier said than done):

    a[n] += a[n-1] + a[n-2]
    -Save the whales. Collect the whole set.

  6. #6
    Sean
    Guest

    Lightbulb

    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. #7
    Sean
    Guest

    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 subscribe to a feed

Similar Threads

  1. fibonacci sequence
    By cph in forum C Programming
    Replies: 57
    Last Post: 04-30-2009, 08:17 AM
  2. n-th element of the fibonacci sequence
    By me001 in forum C Programming
    Replies: 22
    Last Post: 09-24-2008, 04:27 AM
  3. Fibonacci Sequence
    By Dogmasur in forum C Programming
    Replies: 15
    Last Post: 08-10-2008, 08:55 AM
  4. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  5. Fibonacci sequence output statement
    By chocha7 in forum C++ Programming
    Replies: 10
    Last Post: 11-18-2004, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21