1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serggg [28]
3 years ago
12

Write a while loop that prints userNum divided by 4 (integer division) until reaching 2. Follow each number by a space. Example

output for userNum = 160:
40 10 2

Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".

Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Programend never reached." The system doesn't print the test case that caused the reported message.

#include
using namespace std;

int main() {
int userNum;

cin >> userNum;

/* Your solution goes here */

cout << endl;

return 0;
}
Computers and Technology
1 answer:
Slav-nsk [51]3 years ago
4 0

Answer / Explanation:

#include <iostream>  

using namespace std;

int main()  

{    

 int userNum = 0;  

  userNum = 20;    

  cout << userNum << " ";

  while (userNum > 1)    

  {

     userNum = userNum/2;

     cout << userNum << " ";    

  }    

  cout << endl;  

  return 0;  

}

However, we should note that the above codes divides properly but when it gets to 0, it will always give output as 0 instead of terminating the program.

Hence to make it terminate, we include:

while (userNum > 1)    

{

  cout << userNum << " ";    

  userNum = userNum/2;

}    

The above code alternatively should be replaced with int userNum = 0;  .

Also, for the sake of industry best standard and the general principle, we can say:

The general principle is:

while ( <conditional> )

{

  // Use the data

  // Change the data as the last operation in the loop.

}

A for loop provides natural placeholders for these.

for ( <initialize data>; <conditional>; <update data for next iteration> )

{

  // Use the data

}  

If you were to switch to using a for loop, which I recommend, your code would be:

for ( userNum = 20; userNum > 0; userNum /= 2 )

{

  cout << userNum << " ";

You might be interested in
Which plan includes procedures and processes that ensure the smooth functioning of the business even after a disaster?
mamaluj [8]

Answer:

The plan that includes procedures and processes that ensure the smooth functioning of the business even after a disaster is the:

business continuity and disaster recovery plan.

Explanation:

An entity that has good business continuity and disaster recovery plan maintains its full operational activities and processes after a business disaster.   After the business disaster, the entity may even grow bigger, because it has identified critical functions and their dependencies for continued growth.  While the period is a time of recovery, for business entities that are well-prepared, the recovery period offers a unique opportunity for innovation and rapid recovery and development on all fours: organization, processes, people, and performance.

8 0
2 years ago
Read 2 more answers
Wanda manages an application that fluctuates in usage quite a bit. Sometimes it uses quite a few servers with lots of memory and
TEA [102]

Answer:

c. Elasticity

Explanation:

When referring to Cloud Servers this capability is known as Elasticity. It basically describes how able and efficient a server is to automatically implement resources and remove resources in order meet the specific amount of demand at any given moment. Many times a server will not have much demand but will still have all the resources being used by the server. Being able to remove these unused resources so that they are available for other usage is what makes the servers elastic.

8 0
3 years ago
What are the limits of hashing and verifying that files haven’t changed?
earnstyle [38]

The hashing function can take any number of key-value pairs and there is no specific limit to it.

<h3>What is hashing?</h3>

Hashing is a file-based algorithm for producing a fixed-length bit string value. A file is essentially a collection of data blocks. The length of the data is reduced by hashing to a fixed number or key that represents the original string.

When hashing is employed, the hash function may plot all of the keys and values to what the real size of the table is, demonstrating that the hashing function can take any number of key-value pairs with no restriction.

However, if the passwords are hashed in encryption, recovering the passwords is extremely difficult.

Thus, the hashing function can take any number of key-value pairs and there is no specific limit to it.

Learn more about the hashing here:

brainly.com/question/13106914

#SPJ1

5 0
1 year ago
Which type of computer application is apple keynote? a. word processor b. spreadsheet c. presentation d. database e. multimedia
Naily [24]

The type of computer application which apple keynote is, is: c. presentation.

<h3>What is a presentation application?</h3>

A presentation application can be defined as a type of computer application which is designed and developed to avail its end users an ability to create various slides that comprises both textual and multimedia information, which are typically used during a presentation.

This ultimately implies that, apple keynote is an example of a presentation application which is used on computers.

Read more on presentation application here: brainly.com/question/26404012

#SPJ4

4 0
2 years ago
Create pseudocode to compute the volume of a sphere. Use the formula: V= (4/3)* π r3 where π is equal to 3.1416 approximately, w
MA_775_DIABLO [31]

Answer:

In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of the circumference of any circle to its diameter.

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Following a company on likedin is most similar to
    8·1 answer
  • Themes are applied from which tab?
    6·1 answer
  • In 3-5 sentences, describe how you would insert a graph in your word-processing document.
    13·1 answer
  • Can you tell me what is rast
    5·1 answer
  • An internet connection is required to access which type of software?
    5·1 answer
  • Data is best described as
    10·2 answers
  • Need answer ASAP
    8·2 answers
  • Write a recursive method called lengthOfLongestSubsequence(a, b) that calculates the length of the longest common subsequence (l
    15·1 answer
  • b. Write a complete program for the following situation related to setting the speed of a car to preset values before starting a
    5·1 answer
  • If you wish to install a new OS without disturbing the old one so that you can boot to either OS, what type of boot setup should
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!