131k views
2 votes
Write a while loop that prints user_num divided by 2 until user_num is less than 1. sample output for the given program:

2 Answers

6 votes

Explanation:

Since you did not specify what language to use, I am going to us R to write the while loop. With that said, please view the image I have posted.



Write a while loop that prints user_num divided by 2 until user_num is less than 1. sample-example-1
User Jatinder
by
5.9k points
5 votes

Answer:

while(user_num >= 1.0){

printf("%.2f", user_num);

user_num = user_num/2;

}

Explanation:

I am going to write a C code for this.

The first step is read the value of user_num.

After that, inside the while loop, you print the value then divide user_num by 2.

In the print, %.2f prints the float to two decimal cases.

So

float user_num.

scanf("%f\\", user_num);

while(user_num >= 1.0){

printf("%.2f", user_num);

user_num = user_num/2;

}

User Greepow
by
6.3k points