Challenge - 5 Problems
Relational Expressions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of chained relational expressions
What is the output of this MATLAB code snippet?
MATLAB
a = 5; b = 10; c = 15; result = (a < b) & (b < c); disp(result);
Attempts:
2 left
💡 Hint
Recall that relational expressions return logical 1 (true) or 0 (false).
✗ Incorrect
Both conditions (a < b) and (b < c) are true, so the logical AND (&) returns 1.
❓ Predict Output
intermediate2:00remaining
Relational expression with arrays
What is the output of this MATLAB code?
MATLAB
x = [2, 4, 6]; y = [3, 4, 5]; result = x >= y; disp(result);
Attempts:
2 left
💡 Hint
Relational operators compare elements element-wise in arrays of the same size.
✗ Incorrect
Comparing element-wise: 2>=3 is false (0), 4>=4 is true (1), 6>=5 is true (1).
❓ Predict Output
advanced2:00remaining
Result of mixing relational and logical operators
What does this MATLAB code display?
MATLAB
a = 7; b = 5; c = 7; result = (a == c) | (b > a); disp(result);
Attempts:
2 left
💡 Hint
The OR operator (|) returns true if either condition is true.
✗ Incorrect
a == c is true (7 == 7), b > a is false (5 > 7). True OR false is true (1).
❓ Predict Output
advanced2:00remaining
Relational expression with mixed data types
What is the output of this MATLAB code?
MATLAB
x = 3; y = '3'; result = (x == y); disp(result);
Attempts:
2 left
💡 Hint
MATLAB compares numeric and char types differently in relational expressions.
✗ Incorrect
Numeric 3 is not equal to char '3', so the result is 0 (false).
❓ Predict Output
expert2:00remaining
Logical indexing with relational expressions
What is the output of this MATLAB code?
MATLAB
A = [10, 20, 30, 40, 50]; idx = A > 25; result = A(idx); disp(result);
Attempts:
2 left
💡 Hint
Logical indexing selects elements where the condition is true.
✗ Incorrect
Elements greater than 25 are 30, 40, and 50, so result is [30 40 50].