State the value of x after the statement

7.5k Views Asked by At

State the value of x after the statement if P(x) then x := 1 is executed, where P(x) is the statement “x > 1,” if the value of x when this statement is reached is

  1. x = 0.

  2. x = 1.

  3. x = 2.

this answer :

  1. F , x=0

  2. F, x=1

  3. T, x=1

I don't understand the question and answer , can you explain it ?

1

There are 1 best solutions below

0
On BEST ANSWER

I assume that we are working with a pseudo-programmming language and that we are asked to evaluate what happens with the "conditional instruction" :

"if $x > 1$, then set $x := 1$".

When :

  • $x=0$, we have that $0 > 1$ is false; thus the operation of assigning $1$ to $x$ is not performed and $x$ has the value $0$

  • $x=1$, we have that $1 > 1$ is false; thus the operation of assigning $1$ to $x$ is not performed and $x$ has the value $1$

  • $x=2$, we have that $2 > 1$ is true; now the operation of assigning $1$ to $x$ is performed and $x$ change its value to $1$.