Q. 2. (a) Suppose integer variables P, Q and R contain 8, 16 and 24 respectively. Find the value of each of the following logical expressions: (June 2002)
(i) Q .EQ. 8 .AND. .NOT. P .LT. R - 12
(ii) .NOT. (P .GT. Q .OR. R .LT. 7)

(b) Suppose at some stage values of integer variables P, Q and R are respectively 2, 3 and 4. Find the value of the variable S after execution of each pair of statements given below: (Dec. 2002)
(i) P = -P + P * R * * 2 + Q
S = -P + P * R * * 2 + Q
(ii) P = ABS (P - R * Q)/5
S = ABS (P - R * Q)/5

(c) Suppose the integer variables X and Y contain respectively 2 and 7. Find the final values of X and Y in each of the following cases: (Dec. 2002)
(i) If (X .LE. Y) X = X + 5
X = X + 3
(ii) IF (X .EQ. Y + 2) GOTO 15
X = X + 3
15 X = X + Y

Solution. a) Given, P = 8, Q = 16 and R = 24
(i)
Q .EQ. 8 .AND. .NOT. P .LT. R - 12
= 16 .EQ. 8 .AND. .NOT. 8 .LT. 24 - 12
= 16 .EQ. 8 .AND. .NOT. 8 .LT. 12
= F .AND. .NOT. T
= F .AND. F
= F

(ii) .NOT. (P .GT. Q .OR. R .LT. 7)
= .NOT. (8 .GT. 16 .OR. 24 .LT. 7)
= .NOT. (F .OR. F)
= .NOT. (F)
= T

b) (i) P = -P + P * R * * 2 + Q
or P = -2 + 2 * 4 * * 2 + 3
or P = -2 + 2 X (4)2 + 3
or P = 33
S = -P + P * R * * 2 + Q
or S = -33 + 33 * 4 * * 2 + 3
or S = 498

(ii) P = ABS (P - R * Q)/5
or P = ABS (2 - 4 * 3)/5
or P = | 2 - 4 X 3 |/5
or P = | -10 |/5
or P = 10/5
or P = 2
S = ABS (P - R * Q)/5
or S = ABS (2 - 4 * 3)/5
or S = 2

c) (i) The condition is true as X < Y.
X will be incremented by 5 and becomes 7.
Again, X will be incremented by 3 and becomes 10.

(ii) The condition is false as X = 2 and Y + 2 = 9.
X = 2 + 3 = 5
Then X = 5 + 7
Therefore, the final values of X and Y are 12 and 7 respectively.

Q. 3. Suppose the variables A, B and C respectively contain the values 3, 4 and 5. Find the value of each of the following logical expressions: (Dec. 2001)
(i) (A + C) .EQ. 2 * B .AND. 2 * (C - A) .EQ. B
(ii) .NOT. (3 .EQ. C - 2 .AND. A .LE. C)
(iii) .NOT. C .GT. A .OR. B .LT. 5

Solution. Given, A = 3, B = 4 and C = 5
(i) (A + C) .EQ. 2 * B .AND. 2 * (C - A) .EQ. B
= (3 + 5) .EQ. 2 * 4 .AND. 2 * (5 - 3) .EQ. 4
= 8 .EQ. 8 .AND. 4 .EQ. 4
= T .AND. T
= T

(ii) .NOT. (3 .EQ. C - 2 .AND. A .LE. C)
= .NOT. (3 .EQ. 5 - 2 .AND. 3 .LE. 5)
= .NOT. (3 .EQ. 3 .AND. 3 .LE. 5)
= .NOT. (T .AND. T)
= .NOT. (T)
= F

(iii) .NOT. C .GT. A .OR. B .LT. 5
= .NOT. 5 .GT. 3 .OR. 4 .LT. 5
= .NOT. F .OR. T
= T .OR. T
= T



Main Contents Page

© Universal Teacher Publications