Thread: Fibonacci sequence

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    1

    Post Fibonacci sequence

    Im tryin to create a program that allows the user to input a number and it will find the corresponding fiboancci number that is that number in the sequence.

    ex.
    fib sequence 1 1 2 3 5 8 13 21 34

    user inputs : 6

    output : 8

    i was wonderin if someone could help me out Thanx!!

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    19
    This is loops, and this is also probably homework... so all I'm gonna tell you is that it involves one for loop inside of another for loop (if I recall from the last time I did this).. think about it.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    there is no need for nested loop. A single loop would work.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    Code:
    /* deleted */
    Last edited by laserlight; 02-26-2008 at 09:24 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    lastdestined, read the Homework policy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    laserlight, sorry, I will respect the rules later.

    BTW, you can delete my message, I believe that guy haven't seen it yet

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    It's also not a very good algorithm, as it can't count beyond 100 numbers, and because it store all the unneeded intermediate numbers. You really only need to store 3 numbers at a time, and there' no need to make an arbitrary limit like that.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

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, 07:17 AM
  2. n-th element of the fibonacci sequence
    By me001 in forum C Programming
    Replies: 22
    Last Post: 09-24-2008, 03:27 AM
  3. Fibonacci Sequence
    By Dogmasur in forum C Programming
    Replies: 15
    Last Post: 08-10-2008, 07: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