Ask Question
18 September, 23:04

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

+2
Answers (1)
  1. 19 September, 00:50
    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?
Get 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 & 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