Consider the following conditional code, which returns a Boolean values if…

2022

Consider the following conditional code, which returns a Boolean values

if ((𝑥 > 25)&&(𝑦 > 100))
    return 'false';
else iff (𝑥 ≤ 25)&&&(𝑦 ≤ 100))
    return 'true';
else iff (𝑥 > 25) && (𝑦 ≤ 100))
    return 'false';
else
    return 'true';

Simplify it by filling in the following blank with a single Boolean expression without changing the behaviour of the conditional code.

if (_ _ _ _ _ _ _ _ _)
    return 'true';
else
    return 'false';

  1. A.

    𝑥 > 25

  2. B.

    𝑥 ≤ 25

  3. C.

    𝑦 > 100

  4. D.

    𝑦 ≤ 100

Attempted by 318 students.

Show answer & explanation

Correct answer: B

Simplified condition: x ≤ 25

Reasoning:

  1. Case 1: x > 25 and y > 100 → returns false (first branch).

  2. Case 2: x > 25 and y ≤ 100 → returns false (third branch).

  3. Case 3: x ≤ 25 and y ≤ 100 → returns true (second branch).

  4. Case 4: x ≤ 25 and y > 100 → returns true (else branch).

Conclusion: For both values of y, the function returns true exactly when x ≤ 25 and returns false when x > 25. Therefore the conditional can be simplified to if (x ≤ 25) return true; else return false;.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor