cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Hailstone sequence
Hailstone sequence
Sep 15, 2016 at 12:24am UTC
Falcon612
(6)
I cant figure out how to return the largest number in a hailstone sequence while using a loop and no recursion.
My sequence is {7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1}
The answer my code is giving me is 22.
int largestNum(int n)
{
int t = 0;
int k = 0;
while(k != n)
{
k++;
t = max(next(n), length(n));
}
return t;
}
Sep 15, 2016 at 12:28am UTC
SamuelAdams
(1535)
a loop is recursion.
Sep 15, 2016 at 12:29am UTC
Falcon612
(6)
I need to use a loop, any advice would be helpful.
Sep 15, 2016 at 12:08pm UTC
fcantoro
(81)
The first advice is:
post a compilable code (with code tags, see
http://www.cplusplus.com/articles/jEywvCM9/)
to reproduce the problem.
After that, I'm sure you will get other advices.
Topic archived. No new replies allowed.