Question

Control Structures and Subroutines

I. A while loop whose condition is not made false is called an infi nite loop. However, it is infinite, in the sense of continuing to run forever, only in theory. The loop will stop at some point. Why? 2. To evaluate the if statements in this question below, assume that a Print statement simply prints whatever is in quotes after it. The phrases after a semicolon in the third code fragment are comments and are meant to explain the code. Also assume the following variables have the values give A=5 ·C =7 For each pseudocode fragment below, write what would be printed in the case of the values given above. (a) If A < B then Print the first thing (b) If C-D then Print the first thing (c) If C > D then Print the first thing (d) If A 5 then if B < C then Print the first thing.. else Print the second thing else Print the second thing Print the second part ;else for second if: else Print the second thing else for first if: else Print the third thing (e) If A 5 then if B > C then Print the first thing.. else Print the second thing else Print the third thing (f) If A = 4 then if B < C then Print the first thing. else Print the second thing else Print the third thing

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.when the memory alloted will exhaust,at that that the while loop will stop.because it cannot hold more numbers due to memory deficit

2.a) the first string //the condition is true because a is more than b

b) will not compile//error because = means assignment and it is not used inside if..equal to should be ==

c) the first thing //value of c is more than d.so cndition is true

d)the first thing //the condition is true.c is smaller than d

e)the second thing //c is smaller than b

f) the first thing //b is less than c

3) error because jth loop is not mentioned or given and it is tried to increment.for program to work it should be i which must be incremented

4)if i=i+2 is used after the print statement, then message will be printed 5 times

5) 5 4 3 2 1. //because value of j will print and decrement from 5 to 0.

6)

7)


Step 1: begin
Step 2:Set j to 1
Step 3: if j > n then go to step 7
Step 4: if A[i] = x then go to step 6
Step 5: Set j to j + 1
Step 6: Go back to Step 2
Step 7: Print Element x Found at index j and go to step 8
Step 8: Print element not found
Step 8: End
Add a comment
Know the answer?
Add Answer to:
Control Structures and Subroutines I. A while loop whose condition is not made false is called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. A tor loop is useful when you know in advance the number of iterations to...

    3. A tor loop is useful when you know in advance the number of iterations to be executed. The tor loop consists of three parts each of which is separated by a semicolon (:). The first part is initialization of the variable for iteration, the second part is a test of the iteration variable and if this test fails, the loop is finished. The third part is a counter for the iteration variable. A block can be followed after the...

  • e. Code a while loop that determines and prints the winnings for the Daytona 500 depending...

    e. Code a while loop that determines and prints the winnings for the Daytona 500 depending upon the position after the finish-line: 1st, 2nd, or 3rd. Assume the input variable for the Scanner class, position and prizeMoney variables are already declared. Declare noWinners variable, and initialize it to the number of winners.    Declare a counter-control variable for the while loop, and initialize it. When the loop is entered, prompt: The driver crossed the finish line in which place? Insert the...

  • Question 21 The loop condition can be a complex condition involving several operators. True OR False...

    Question 21 The loop condition can be a complex condition involving several operators. True OR False Question 22 final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; if(num3-5 >= 2*LIMIT) { System.out.println ("apple"); } else { System.out.println ("orange"); } System.out.println("grape"); What prints? A. Apple B. Orange C. Grape D. apple grape E. orange grape F. Nothing. Question 23 When we use a while loop, we always know in advance how many...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

  • I am writing python code. I submitted an assignment but the professor said it was a...

    I am writing python code. I submitted an assignment but the professor said it was a modularization. Can you help me see what part of the code is modularization? Pseudocode: 1. Decalre MainMethod () function: # A. Parameters: Three numbers # B. Put the three numbers in reverse # 2. Main Program # A. Initialize Varibles # B. Accepts three values from the user # C. Invoke MainMethod () function, passing the three numbers as arguments in reverse # D....

  • The loop below stores the values 1 to 5 in myList: for (int i = 0;...

    The loop below stores the values 1 to 5 in myList: for (int i = 0; i < 5; i ++) { myList [ i ] = i + 1; //store values using a loop } The loop below prints the values from first to last in myList: for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " "); } Use the examples on the slides to complete the lab below. Please submit the...

  • Linux & C code help with creating a child process and kills itself with SIGNAL. I...

    Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you! A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm()...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • Python Testing a) The temperature readings are correctly handled using a while loop and the output...

    Python Testing a) The temperature readings are correctly handled using a while loop and the output is correct b) The wind speed readings are correctly handled using a while loop and the output is correct c) The humidity readings are correctly handled using a while loop and the output is correct d) Works correctly overall The program first prompts for and reads in temperatures (all integers), until a line with no characters in received. It computes the average of all...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT