Computer Science, asked by pradeeptuk2, 7 months ago

How many times does the following code segment executeint x=1, y=10, z=1;
do{y-- X++; y-=2; y=z; Z++} while (y>1 && z<10); *
OD) infinite
O A)1
OB) 10
OC) 5​

Answers

Answered by zaaranatalwala786
1

Answer:

i think your answer is infinite according to Google

Answered by pruthaasl
0

Answer:

The given code segment executes A)1 time.

Explanation:

The given code segment is as follows:

x = 1, y = 10, z = 1;

do{

y--;

x++;

y-=2;

y=z;

z++;

} while(y>1 && z<10);

  • The initial values of x, y, and z are 1, 10, and 1 respectively.
  • Once the do-while loop is started, the value of y is decremented. So, y is changed from y = 10 to y = 9.
  • Next, the value of x is incremented from x = 1 to x = 2.
  • Then again the value of y is reduced by to. Hence, y becomes y=9-2, i.e., y = 7.
  • Now, the value of z is assigned to y. So, y becomes y = 1 since z = 1.
  • The value of z is incremented from z = 1 to z = 2.
  • The do-while loop is executed once. Now the condition for the next iteration is checked.
  • The second iteration takes place if the value of y is greater than 1 and the value of z is less than 10.
  • By the end of the first iteration y = 1 and z = 2. Hence, y>1 will give a false result and z<10 will give a true result.
  • Therefore, the logical AND of the two results will be 0 and the loop will not be iterated.

Therefore, the given code executes 1 time.

#SPJ3  

Similar questions