What is the value of y after execution of the following code

What is the value of y after execution of the following code?

What is the value of y after execution of the following code? x: = 3 y: = 2 if (xy > 3) then x: = x + y else if (xy

Solution

Answer: y value is 17

At line 1, x value is 3

At line 1, y value is 2

if(xy > 3) condition will return true so under this block statements will execute

x = x+ y i.e x = 3 + 2so x = 5 now.

Other else if blocks will not execute.

Now for loop will execute. it will start from1 to 5. Each value will get added to y .

So at the end of loop y value will becoe 17

y = 2 + 1 = 3

y = 3 + 2 = 5

y = 5 + 3 = 8

y = 8 + 4 = 12

y = 12 + 5 = 17

What is the value of y after execution of the following code? What is the value of y after execution of the following code? x: = 3 y: = 2 if (xy > 3) then x:

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site