Given the commands below what is the final value of z x 1 z

Given the commands below, what is the final value of z? x = 1 z = 7 Do z = x*2 + z X = X + 1 If x > 3 Then Exit Do

Solution

initially x=1
goes into the loop z= 1*2+7 = 9
x=2 now. Condition is false as x<3
again executes the loop
z= 2*2+9 = 13
x=3 now. Condition is false as x=3
z= 3*2+13 = 19
x=4 now. Condition is true as x<3
final value of z= 19

 Given the commands below, what is the final value of z? x = 1 z = 7 Do z = x*2 + z X = X + 1 If x > 3 Then Exit DoSolutioninitially x=1 goes into the loop z

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site