Question

Given the following while loop, what is the value assigned to variable z for the given...

Given the following while loop, what is the value assigned to variable z for the given values of variables a, b and c?

mult = 0;

while (a < 10) { mult = b * a; if (mult > c) {

break;

}

a = a + 1;

}

z = a;

a = 4, b = 5, c = 20

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

Answer

a, b, c = 4, 5, 20
mult = 0;
while (a < 10) {
    mult = b * a;
    if (mult > c) {
        break;
    }
    a = a + 1;
}
z = a;

iteration 1:
-------------
mult = 5*4 = 20
mult > c => 20 > 20 is false. so, loop will not break
a = a+1 = 4+1 = 5

iteration 2:
-------------
mult = 5*5 = 25
mult > c => 25 > 20 is true. so, the loop will break.

so, final value of a after the loop ends is 5. hence the variable z is set a value of 5.
Answer: 5



Please let me know if you have any doubts Please upvote this answer. Thank s!!

Add a comment
Know the answer?
Add Answer to:
Given the following while loop, what is the value assigned to variable z for the given...
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
  • 11) 16 pts. Convert the following for loop to a while loop. (You may want to...

    11) 16 pts. Convert the following for loop to a while loop. (You may want to do the following question first.) int mine [5] = {10, 11, 12); for (int j=1; j < 5; j++) cout <<j<< "" << mine[jl <<" " << end1; 12) 6 pts. What is the output of the previous question? 13) 4 pts. Circle the variables that would NOT cause syntax errors 2-smaTT , entry# break -my-int

  • 2. What is the output of the following code fragment? n = 1; while (n <=...

    2. What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; a.1 2 3 4 5 b. 1 2 3 4 c. 1 1 1 forever d. 2 3 4 5 e. 2 3 4 5 6 3. What is the termination condition for the following While loop? while (beta > 0 && beta < 10) { cout << beta << endl; cin >> beta; }...

  • C++ help! #4,6,7 c) no-test d) loop-test e) None of these 1. Which of the following...

    C++ help! #4,6,7 c) no-test d) loop-test e) None of these 1. Which of the following variable names is invalid? a) numstudents b) 2Darray c) studentHame d) test Grade 祁.which of the following conditions is true ifX has a value of 10 and T has a value of 20? None of these 2. In Ca4, the operator indicates: a) subtraction b) negation c) equality e) None of these . What are the final values of z and y after the...

  • A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume...

    A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...

  • CODE MUST BE IN C 1. Given an int variable n that has been initialized to...

    CODE MUST BE IN C 1. Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alreadybeen declared, use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and...

  • A for loop is given below. Use a while loop to perform the same task. for(...

    A for loop is given below. Use a while loop to perform the same task. for( i=0;i<=7;i+=2) { Sum=Sum + i; } b: What is value of variable Sum after the end of loop?

  • Convert the following while loop into a for loop. int 1 - 50: int sum-07 while...

    Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;

  • whats the answers How many total integers elements are in an array with 4 rows and...

    whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...

  • Please answer both questions thank you. Rewrite the following for loop into a while loop: int...

    Please answer both questions thank you. Rewrite the following for loop into a while loop: int s S = 0; for (int i = 1; i <= 10; i++) { S += i; int s = 0; int i = while (i <= 10) S = + i; i++; } int s = 0; int i = 1; while (i <= 10) { s = s + i; i++; } int S = 0; int i = 1; while (i...

  • In Javascript: While loop: use a while loop to calculate and display the Kelvin temperature values...

    In Javascript: While loop: use a while loop to calculate and display the Kelvin temperature values for each Fahrenheit temperature value range from 0 to 100 in increment of 10. use the formula tk = (tf -32) x 5/9 + 273.15    The values should be displayed exactly as shown: -17, -12, -6, -1, 4, 10, 15, 21, 26, 32, 37

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