Solution Found!
What is the value of x after each of these statements is
Chapter 1, Problem 42E(choose chapter or problem)
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?
Questions & Answers
QUESTION:
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?
ANSWER:Solution:Step-1:a)In this problem we need to find the value of x after each of the given statements is encountered in a computer program, if x=1 before the statement is reached.The given statement is: if x+2 = 3 then If x = 1 then x +2 =1+2 = 3 .Therefore, if x =1 then x+2 = 3 is true.So, the statement is encountered.If x = 1 then = 1+1 = 2. Therefore, if x =1 then .Thus, x has the value after encountered is x= 2.Step-2:b)In this problem we need to find the value of x after each of the given statements is encountered in a computer program, if x=1 before the statement is reached.The given statement is: if (x+1 = 3) or (2 x+2=3) then If x = 1 then x +1 =1+1 = 2 .Therefore, if x =1 then x+1 = 3 is false.If x = 1 then 2x+2 =2(1)+2 = 4 .Therefore, if x =1 then 2 x+2 = 3 is false.Now, the representation of (x+1 = 3) or (2 x+2=3) is f