Question & Answer: What is the value of x after each of these statements is encountered in a computer program if x = 1 b…..

What is the value of x after each of these statements is encountered in a computer program if x = 1 before the statement is reached.
a. If x + 2 = 3 then x:=x + 1

b. If (x + 1 = 3) OR (2x + 2 = 3) then x := x +1

c. If ((2x + 3) = 5) AND (3x + 4 = 2) then x:= x + 1

d. If x < 2 then x := x + 1

Expert Answer

 

x=1;

a)

if x+2=3 then x:=x+1;

Ans-

x+2=3

1+2=3

3=3   so x:=1+1;

x:=2;

b)

if((x+1=3)OR(2X+2=3))then x:=x+1;

Ans-

(x+1=3)OR(2X+2=3)

(1+1=3)OR(2*1+2=3)

(2=3)OR(4=3)

false OR FALSE

BOTH ARE FALSE SO false

X=1;

d) if(x<2)then x:=x+1;

Ans-

(1<2)

true

so

x:=x+1;

=1+1;

=2;

Still stressed from student homework?
Get quality assistance from academic writers!