149k views
5 votes
Write a while loop that prints usernum divided by 2 (integer division) until reaching 1. follow each number by a space. example output for usernum = 40: 20 10 5 2 1

User Emad Ha
by
9.1k points

2 Answers

0 votes

Answer:

while(userNum > 1){

userNum = userNum /2;

System.out.print(userNum+" ");

}

Explanation:

Not all heros wear capes.

Write a while loop that prints usernum divided by 2 (integer division) until reaching-example-1
User Etherman
by
8.4k points
3 votes
In the following code snippet,
N = usernum, which is the input number
m = round(x) means that the decimal quantity x is rounded to the nearest integer, m
The symbol # denotes a comment(s) so that everything after the # symbol is ignored as part of the code.
In a while loop, True is represented by the number 1, and False is represented by the number 0.

N = inpu("Enter input number"); # Receive input number
x = N; # store the input number in the variable x

while 1 # begin the while loop
m = round(N/2); # divide x by 2 and round to the nearest integer
print m; # print the value of m
print ' '; # print a space
# If m <=1, break out of the loop
if m<=1
break
end

end # end of the loop


User MoRe
by
8.3k points