Ask Question
10 July, 12:20

Write a while loop that prints usernum divided by 2 until user_num is less than 1. The value of user_num changes inside of the loop. Sample output with input: 20 10.0 5.0 2.5 1.25 0.625

+4
Answers (1)
  1. 10 July, 15:10
    0
    The program to this question can be describes as follows:

    Program:

    #include / /defining header file

    using namespace std;

    int main () / /defining main method

    {

    float user_num; //defining float variable

    cout<<"Enter any number: "; / /message

    cin>>user_num; / /input value from the user

    while (user_num > = 1) / /defining loop to calculate value

    {

    user_num = user_num / 2; / /diving the value

    cout<
    }

    return 0;

    }

    Output:

    Enter any number: 20

    10

    5

    2.5

    1.25

    0.625

    Explanation:

    In the above program, a float variable user_num is declared in which we store input value from the user end, in the next step, a while loop is declared, which calculates, the given value.

    In the loop a condition is defined, that user_num value is greater than equal to 1, inside the loop it will divide the value of the user_num and store in this variable. In this print, the method is used, which prints its variable values.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a while loop that prints usernum divided by 2 until user_num is less than 1. The value of user_num changes inside of the loop. Sample ...” 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