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

Respuesta :

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

 

Answer:

while(userNum > 1){

        userNum = userNum /2;

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

     }

Step-by-step explanation:

Not all heros wear capes.

Ver imagen DarthVaderBarbie