Challenge - 5 Problems
Arithmetic Operators Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of mixed arithmetic operations
What is the output of the following MATLAB code?
MATLAB
a = 5; b = 3; c = a^2 - 4*b + 7; disp(c);
Attempts:
2 left
💡 Hint
Remember the order of operations: powers first, then multiplication and subtraction.
✗ Incorrect
The code calculates 5^2 - 4*3 + 7 = 25 - 12 + 7 = 20.
❓ Predict Output
intermediate2:00remaining
Division and modulus output
What is the output of this MATLAB code snippet?
MATLAB
x = 17; y = 5; q = floor(x / y); r = mod(x, y); disp([q, r]);
Attempts:
2 left
💡 Hint
Use floor division for quotient and mod for remainder.
✗ Incorrect
17 divided by 5 is 3.4. Floor division gives 3.
Remainder is 17 - 5*3 = 2.
So output is [3 2].
❓ Predict Output
advanced2:30remaining
Result of element-wise vs matrix multiplication
What is the output of this MATLAB code?
MATLAB
A = [1 2; 3 4]; B = [2 0; 1 3]; C = A .* B; D = A * B; disp(C); disp(D);
Attempts:
2 left
💡 Hint
Remember that .* is element-wise multiplication and * is matrix multiplication.
✗ Incorrect
Element-wise multiplication multiplies each element individually:
C = [1*2 2*0; 3*1 4*3] = [2 0; 3 12]
Matrix multiplication:
D = [1*2+2*1 1*0+2*3; 3*2+4*1 3*0+4*3] = [4 6; 10 12]
❓ Predict Output
advanced2:00remaining
Output of combined arithmetic and logical operations
What is the output of this MATLAB code?
MATLAB
x = 4; y = 7; z = (x > 3) + (y < 5) * 10; disp(z);
Attempts:
2 left
💡 Hint
Logical expressions return 1 for true and 0 for false. Multiplication has higher precedence than addition.
✗ Incorrect
(x > 3) is true (1), (y < 5) is false (0).
Multiplication has higher precedence: 0 * 10 = 0, then 1 + 0 = 1.
❓ Predict Output
expert2:30remaining
Output of chained arithmetic with parentheses
What is the output of this MATLAB code?
MATLAB
a = 2; b = 3; c = 4; d = a + b * c ^ a - (b + c) * a; disp(d);
Attempts:
2 left
💡 Hint
Remember the order: parentheses, exponentiation, multiplication/division, addition/subtraction.
✗ Incorrect
Step by step:
c ^ a = 4^2 = 16
b * 16 = 3 * 16 = 48
(b + c) * a = (3 + 4) * 2 = 14
a + 48 - 14 = 2 + 48 - 14 = 36