Examine the following code for (int x = 1; x < 34; x = x + 2) { x = x % 40; x = x - 1; MessageBox.Show(x.ToString()); } How many times is this loop going to iterate (body is going to execute)
Ans : 33 Times
Explanation :
0 x = 1, x = 1%40 = 1, x = x-1 , x = 1-1 = 0 1 x = 2 x = 2%40 = 2, x = x-1 , x = 2-1 = 1 2 x = 3 x = 3%40 = 3, x = x-1 , x = 3-1 = 2 3 x = 4, x = 4%40 = 4, x = x-1 , x = 4-1 = 3 4 x = 5, x = 5%40 = 5, x = x-1 , x = 5-1 = 4 5 x = 6, x = 6%40 = 6, x = x-1 , x = 6-1 = 5 6 x = 7, x = 7%40 = 7, x = x-1 , x = 7-1 = 6 7 x = 8, x = 8%40 = 8, x = x-1 , x = 8-1 = 7 8 x = 9, x = 9%40 = 9, x = x-1 , x = 9-1 = 8 9 x = 10, x = 10%40 = 10, x = x-1 , x = 10-1 = 9 10 x = 11, x = 11%40 = 11, x = x-1 , x = 11-1 = 10 11 x = 12, x = 12%40 = 12, x = x-1 , x = 12-1 = 11 12 x = 13, x = 13%40 = 13, x = x-1 , x = 13-1 = 12 13 x = 14, x = 14%40 = 14, x = x-1 , x = 14-1 = 13 14 x = 15, x = 15%40 = 15, x = x-1 , x = 15-1 = 14 15 x = 16, x = 16%40 = 16, x = x-1 , x = 16-1 = 15 16 x = 17, x = 17%40 = 17, x = x-1 , x = 17-1 = 16 17 x = 18, x = 18%40 = 18, x = x-1 , x = 18-1 = 17 18 x = 19, x = 19%40 = 19, x = x-1 , x = 19-1 = 18 19 x = 20, x = 20%40 = 20, x = x-1 , x = 20-1 = 19 20 x = 21, x = 21%40 = 21, x = x-1 , x = 21-1 = 20 21 x = 22, x = 22%40 = 22, x = x-1 , x = 22-1 = 21 22 x = 23, x = 23%40 = 23, x = x-1 , x = 23-1 = 22 23 x = 24, x = 24%40 = 24, x = x-1 , x = 24-1 = 23 24 x = 25, x = 25%40 = 25, x = x-1 , x = 25-1 = 24 25 x = 26, x = 26%40 = 26, x = x-1 , x = 26-1 = 25 26 x = 27, x = 27%40 = 27, x = x-1 , x = 27-1 = 26 27 x = 28, x = 28%40 = 28, x = x-1 , x = 28-1 = 27 28 x = 29, x = 29%40 = 29, x = x-1 , x = 29-1 = 28 29 x = 30, x = 30%40 = 30, x = x-1 , x = 30-1 = 29 30 x = 31, x = 31%40 = 31, x = x-1 , x = 31-1 = 30 31 x = 32, x = 32%40 = 32, x = x-1 , x = 32-1 = 31 32 x = 33, x = 33%40 = 33, x = x-1 , x = 33-1 = 32
Do ask if any doubt. Please upvote.
What will be the value of x after the following code is executed? int x = 5; while (x <50) { x += 5; } a) 50 b) 45 c) Infiniteloop d) 55 Given the following code segment: Scanner in = new Scanner (System.in); boolean done = false; while (!done) { int input = in.next(); if(input.equalsIgnoreCase("q")) done = false; } What will cause the loop to terminate? a) When the user enters -1 b) The loop will never terminate c)...
whats the answers
For the following code, indicate how many times the loop body will execute for the following input values: 2 1 0? userNum - 3 while (userNum > 0) { // Do something // Get user um from input } 3 Given the following code, how many times will the inner loop body execute? int row: int col; for (row = 0; row < 2; row - row + 1) { for (col = 0; col < 3;...
In the code given below, how many times the cout statement is executed? for (int x = 0; x< 10; x++) for (int y=0; y < 10; y++) for (int z = 0; z <=10; z++) cout << X+y+z;
Which statement best describes what will occur if we execute the following code? int x; x = 11.6;
how many times will the following loop execute? For intCount = To 1 Step -2 'Body of loop Next A. 4 B. 5 C. 9 D. 10
What will be the output of the following code int x = 5; int y = 2; f(x,y); printf(“%s \n”, (x/y > 2) ? “x is more than two times larger than y” : “x is less than or equal to 2*y\n ”); f(int x, int y) { x = 2*y; printf(“%s \n”, (x/y > 2) ? “x is more than two times larger than y” : “x is less than or equal to 2*y \n”); } a. x is...
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...
5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, answer the following: (a) Convert the above C code to MIPS assembly. (b) The condition you are testing is met at Case 1. You do not want the Case 2 to be tested. Add appropriate instructions in MIPS for this implementation. (c) If int x is any integer other than 1 or 2, you...
Question 15 The following code displays main() int *p; P = (int*) malloc(sizeof(int)); *P = 10; printf("p = d\n", *p); 10 1542 (address of p) 20 None of the above Moving to another question will save this response > Moving to another question will save this response. Question 16 How many times the following code prints the string 'hello for(i=1;i<=1000; i++); printf("hello"): 1000 Zero 20 Moving to another question will save this response
C++ Visual Studio 1. How many iterations are in the following "while" loop? int i = 0; while(i < 20) { ++i; } 2. How many iterations are in the following "for" loop? for(int i = 5; i < 17; i = i + 2) { // Work } How many times will '+' be printed? int i = 0; while(true) { if(i == 5) { break; } cout << "+"; ++i; } 3. How many times will '+' be...