Ask Question
27 June, 23:18

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

+4
Answers (1)
  1. 27 June, 23:29
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a while loop that prints usernum divided by 2 (integer division) until reaching 1. follow each number by a space. example output for ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers