Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

41. match the conditional expression with the if/else statement that pe…

Question

  1. match the conditional expression with the if/else statement that performs the same operation.

a) q = x < y? a + b : x * 2;
b) q = x < y? x * 2 : a + b;
c) x < y? q = 0 : q = 1;
if (x < y)
q = 0;
else
q = 1;
if (x < y)
q = a + b;
else
q = x * 2;
if (x < y)
q = x * 2;
else
q = a + b;

Explanation:

Step1: Analyze the first if - else statement

The first if - else statement is if (x < y) q = 0; else q = 1;. In conditional expression form, it is x < y? q = 0 : q = 1, which matches option C.

Step2: Analyze the second if - else statement

The second if - else statement is if (x < y) q = a + b; else q = x 2;. In conditional expression form, it is q = x < y? a + b : x 2, which matches option A.

Step3: Analyze the third if - else statement

The third if - else statement is if (x < y) q = x 2; else q = a + b;. In conditional expression form, it is q = x < y? x 2 : a + b, which matches option B.

Answer:

First blank: C
Second blank: A
Third blank: B