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...
Re: C++ hailstone sequence problem
1 Attachment(s)
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
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.
Re: C++ hailstone sequence problem
Quote:
Originally Posted by
Lindley
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...