Ask Question

Write a program to prompt the user for a positive integer: N. The program will repeatedly divide the input in half using a loop, discarding any fractional part, until it becomes 1. The program should print on separate lines:

• the sequence of 'halved' value, one per line

• the number of iterations required

• the value of log2 (N)

+5
Answers (1)
  1. 19 July, 21:30
    0
    using python to write the program

    Explanation:

    #To use the log function, the module must be imported

    import math

    n=int (input ("Enter number to be halved"))

    count=0

    while (n>1):

    count=count+1

    n=n//2

    print ("The number halved is now ", n, "The is the ", count, "iteration")

    x = math, log (2, (n))

    print ("The log of n is:", x)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program to prompt the user for a positive integer: N. The program will repeatedly divide the input in half using a loop, discarding ...” in 📗 Computers & Technology 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