|
-
September 24th, 2010, 03:43 PM
#10
Re: Hailstone Sequence Problem
You don't need an extra loop to track the maximum; you can just do that "on the fly" in the outermost loop (for) in main().
A short breakdown on how to do it: Declare a variable for the maximum before entering the loop, and initialize it to an impossibly low maximum value. 0 would be a natural choice for that. During each of the iterations, check whether the current sequence length is greater than the maximum you have so far, and if yes, adjust the maximum accordingly. Once you're done with the loop, you have your maximum.
The C++ code required to do this, BTW, would be much less characters than my description above. 
HTH
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|