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
geniusboy [140]
3 years ago
6

4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Fol

low each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, 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 "Program end never reached." The system doesn't print the test case that caused the reported message.

Computers and Technology
2 answers:
Grace [21]3 years ago
7 0

Answer:

def dividedByTwo(userNum):

   out = []

   num = userNum  

   while num > 1:

       num = num//2

       out.append(num)

   try:

       if out[-1]==1:

           print(str(userNum) + ': ' + str(out))

       else:

           print("Program end never reached.")

   except:

       print("Program end never reached.")

userNum = int(input())

dividedByTwo(userNum)

Explanation:

We created a function called dividedByTwo that receives the user input, inside the function is a while loop that just allows numbers greater than one to avoid an infinite loop, this while loop will finish when the division reaches one; finally, an if statement checks if 1 was reached, otherwise, an error message will prompt.

The output of the testing in the image down below

wlad13 [49]3 years ago
4 0

Answer:

import java.io.*;

import java.util.Scanner;

class divide {

public static void main (String[] args) {

    Scanner num=new Scanner(System.in);//scanner object.

    int userNum=num.nextInt();

    while(userNum>1)//while loop.

    {

        userNum/=2;//dividing the userNum.

        System.out.print(userNum+" ");//printing the userNum.

    }

}

}

Input:-

40

Output:-

20 10 5 2 1

Input:-

2

Output:-

1

Input:-

0

Output:-

No Output

Input:-

-1

Output:-

No Output.

Explanation:

In the program While loop is used.In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.The inputs and corresponding outputs are written in the answer.

You might be interested in
How many coulombs of charge do 50 * 10^31 electrons possess
Gemiola [76]
Is there anything else to it

5 0
3 years ago
When troubleshooting your BranchCache configurations, what specific commands will allow you to verify that all your clients are
beks73 [17]

Netsh branchcache show status all commands will allow you to verify that all your clients are using the same caching mode, caching is enabled, and the cache is not full.

d. netsh branchcache show status all

<u>Explanation:</u>

In network BranchCache is basically called optimizing band width in wide area network. End user has to check whether BranchCache is enabled or not. BranchCache is normally done windows server side for web server or application server or cloud technology. Network administer has to monitor the bandwidth usage and take necessary steps.

Network administrator monitors each client request and checks cache and do alternate source of or content management. Network administrator or end user will know by right click on administrative temple, computer configuration.

5 0
3 years ago
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the t
Monica [59]

Answer:

int SmallestNumber(int num1, int num2, int num3){

int smallest;

if (num1 >num2){

smallest=num2;

}

else {

smallest=num1;

}

if(smallest <num3){

smallest=num3;

}

}

int LargestNumber(int num1, int num2, int num3){

int largest;

if (num1 <num2){

largest=num2;

}

else {

largest=num1;

}

if(largest>num3){

largest=num3;

}

}

void main(){

int num1,num2,num3;

printf("enter values");

scanf("%d%d%d",&num1,&num2,&num3);

int smallest=SmallestNumber(num1,num2,num3);

int largest=LargestNumber(num1,num2,num3);

}

Explanation:

we are comparing first two numbers and finding largest among those. After getting largest comparing that with remaining if it is greater then it will be largest of three. Same logic applicable to smallest also

7 0
3 years ago
Jude is a part of a publishing house. He does editing work for them and often comes across articles that have materials copied f
Butoxors [25]

Answer: The guy in the story did copyright

Explanation:

I am not to sure about this but this is my best guess hope it helps!!

5 0
2 years ago
Can I major in gaming like not game design but like gaming where I can earn money
lozanna [386]

Answer:

yes some companies offer jobs in testing games for them to help find glitches and such before they go onto the market

7 0
3 years ago
Read 2 more answers
Other questions:
  • In addition to regular watch features, which two features are often found on smart watches?
    13·1 answer
  • Of the following which would be the best data representation for this puzzle in a puzzle class?
    6·1 answer
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    11·1 answer
  • This type of software works with end users, application software, and computer hardware to handle the majority of technical deta
    12·1 answer
  • If you must use a credit card while in college what are some ways you can keep from getting in credit card debt?
    15·1 answer
  • in a deisgn project, what two types of graphics or images is the digital artist respondsible for creating?
    11·1 answer
  • Which expression is equivalent to 3x + 3x + 3x?<br><br> From Performance Matters
    11·2 answers
  • What does the top level domain in a url inducate? A. The organization or company that owns the website. B. The organization or c
    6·2 answers
  • Why does my internet keep disconnecting and reconnecting.
    9·1 answer
  • List one unprofessional AND one professional example of internet/social media
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!