Ask 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 userNum = 20:

20 10 5 2 1

existing code:

#include

using namespace std;

int main () {

int userNum = 0;

userNum = 20;

/*Your solution goes here*/

cout << endl;

return 0;

}

+4
Answers (1)
  1. 14 December, 19:00
    0
    while (userNum>0) / /while loop.

    {

    cout<
    userNum/=2; //dividing the userNum.

    }

    Explanation:

    The above-written code should be inserted in the place of the comment your solution should be placed here. In my code I have used a while loop that will run till the userNum is greater than 0. In the loop, I am constantly printing the userNum and dividing it by 2 after printing. This loop will print the same output as written in the question.
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 📗 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