function threekplusone (k) : while k != 1 do rounds = 0 %3D if k%2 == 0 then k/2 else 3*k+1 end if rounds rounds + 1 if rounds == 1000 then quit else print k end if end while end function

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter8: Advanced Data Handling Concepts
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

given k positive integer, if k is even we divide it by 2, if odd we multiply it by 3 and add 1. and we reach 1 eventually. and it stops after 1000 iterations.

below is the code to this algorithm, find the errors from the pseudocode and correct them.

function threekplusone (k) :
while k != 1 do
rounds
%3D
if k%2
0 then
k/2
else
3*k+1
end if
rounds = rounds + 1
%3D
if rounds
1000 then
quit
else
print k
end if
end while
end function
Transcribed Image Text:function threekplusone (k) : while k != 1 do rounds %3D if k%2 0 then k/2 else 3*k+1 end if rounds = rounds + 1 %3D if rounds 1000 then quit else print k end if end while end function
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Matrix multiplication
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr