Ask Question
29 April, 11:51

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;

}

+3
Answers (1)
  1. 29 April, 12:29
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers