Ask Question
10 November, 13:59

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;

}

+1
Answers (1)
  1. 10 November, 15:42
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers