C++ hailstone sequence problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: C++ hailstone sequence problem

  1. #1
    Join Date
    Sep 2011

    Unhappy C++ hailstone sequence problem

    Write a program which:

    requests as input from the user two positive integers s and e, such that s < e.
    outputs (i) the integer n belonging to [s,e] that generates the longest Hailstone sequence Sn, and (ii) the length of this longest Sn

    i have no idea about how to use functions to implement this task...

  2. #2
    Join Date
    Sep 2004
    Holland (land of the dope)

    Re: C++ hailstone sequence problem

  3. #3
    Join Date
    Sep 2011

    Question Re: C++ hailstone sequence problem

    this is where i am, i don't know how to start from the lower number and go up to the larger number, also how to calculate the longest sequence you can get
    Attached Files Attached Files

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Fairfax, VA

    Re: C++ hailstone sequence problem

    Presumably you would implement a function to compute the "hailstone sequence" (whatever that is) for a given value, and then return the length of the sequence. You would then simply call this function multiple times in a loop from s to e and record the largest result.

    EDIT: Wikipedia contains pseudocode for the hailstone function.

  5. #5
    Join Date
    Jun 2010

    Re: C++ hailstone sequence problem

    Quote Originally Posted by Lindley View Post
    Wikipedia contains pseudocode for the hailstone function.
    Also, IIRC, there has been a discussion about that in this very forum section some months ago. I'd expect a forum search to discover interesting information...
    Last edited by Eri523; September 30th, 2011 at 05:06 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


HTML5 Development Center