# Arithmetic

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Arithmetic – 1”.

1. What would be the output of the following code (in editor window)?

`A = [0 1; 1 0]	;	B=2	;	C = A + B`

a)

```   1	2
4	5```

b)

```    2	3
3	2```

c)

```    3	2
3	2```

d)

```    3	2
2	3```

2. What would be the output of the following code (in editor window)?

`A = [1 0 2]	;	b = [3 0 7]	;	c=a.*b;`

a) [2 0 21]
b) [3 0 14]
c) [14 0 3]
d) [7 0 3]

3. What would be the output of the following code (in editor window)?

`a=1:5	;	c=a.^2`

a) [1 25]
b) [1 2 3 4 5]
c) [25 16 9 4 1]
d) [1 4 9 16 25]

4. What would be the output of the following code (in editor window)?

```A = [1	1	0	0]
B = [1	;2	;3	;4]
C=A*B```

a) 0
b) [1 0 0 0]
c) 3
d) [1 2 0 0]

5. What would be the output of the following code (in editor window)?

```A = [1	2;	3	4]
C = A^2```

a) [7 10; 15 22]
b) [1 4; 9 16]
c) [16 9; 4 1]
d) [22 15; 10 7]

6. What would be the output of the following code (in editor window)?

```A=1:5;
B=cumprod(A)```

a) b=[1 2 6 24 120]
b) b=[1 2 3 4 5]
c) b=[5 4 3 2 1]
d) b=[120 24 6 2 1]

7. Create an array of logical values.

```A = [true false true; true true false]
A = 1     0     1
1     1     0
B = cumprod(A,2)```

Find the cumulative product of the rows of A.
a)

```      B = 1     0     0
0     1     0```

b)

```      B = 1     0     0
1     1     0```

c)

```      B = 1     0     0
1     1     1```

d)

```      B = 1     1     0
1     1     0```

8. Find the cumulative sum of the columns of A.

```  A =1     4     7
2     5     8
3     6     9
B = cumsum(A)```

a)

```B = 1     4     7
3     8    15
6    15    24```

b)

```B = 1     4     7
4     9    15
4    15    24```

c)

```B = 1     4     7
3     9    15
6    15    29```

d)

```B = 1     4     7
3     9    15
6    15    24```

9. Create a 4-by-2-by-3 array of ones and compute the sum along the third dimension.

```A = ones(4,2,3);
S = sum(A,3)```

a)

```S = 3     3
3     3
3     3
3     3```

b)

```S = 3     4
3     4
3     4
3     4```

c)

```S = 2     3
2     3
2     3
2     3```

d)

```S = 7     3
5     3
6     3
3     3```

10. Round each value in a duration array to the nearest number of seconds greater than or equal to that value.

```t = hours(8) + minutes(29:31) + seconds(1.23);
t.Format = 'hh:mm:ss.SS'
t = 08:29:01.23   08:30:01.23   08:31:01.23
Y1 = ceil(t)
Y2 = ceil(t,'hours')```

a)

```     Y1 =  08:29:02.00   08:30:02.00   08:31:02.00
Y2 =  09:00:00.00   09:00:00.00   09:00:00.00```

b)

```     Y1 =  08:29:02.00   08:30:02.00   08:31:02.00
Y2 =  08:29:01.23   08:30:01.23   08:31:01.23```

c)

```     Y1 =  08:29:01.23   08:30:01.23   08:31:01.23
Y2 =  08:29:01.23   08:30:01.23   08:31:01.23```

d)

```     Y1 =  008:29:01.23   08:30:01.23   08:31:01.23
Y2 =  09:00:00.00   09:00:00.00   09:00:00.00```

11. What would be the output of the following code (in editor window)?

```X = [1.4+2.3i 3.1-2.2i -5.3+10.9i]
X = 1.4000 + 2.3000i   3.1000 - 2.2000i  -5.3000 +10.9000i
Y = fix(X)```

a) Y = 1.0000 + 2.0000i 3.0000 – 4.0000i -5.0000 +10.0000i
b) Y = 2.0000 + 3.0000i 3.1000 – 2.2000i -5.3000 +10.9000i
c) Y = 1.0000 + 2.0000i 3.0000 – 2.0000i -5.0000 +10.0000i
d) Y = 2.0000 + 3.0000i 3.1000 – 2.2000i -5.3000 +10.9000i

12. Compute 24 modulo 5.

`b = mod(24,5)`

a) b = 3
b) b =4
c) b =5
d) b =6

13. What would be the output of the following code (in editor window)?

```X = [1 2 3;4 5 6;7 8 9];
Y = [9 8 7;6 5 4;3 2 1];
R = rem(X,Y)```

a)

```   R = 1     2     1
4     0     9
1     0     0```

b)

```   R = 1     2     3
3     0     2
1     0     0```

c)

```   R = 1     2     3
4     1     2
1     1     0```

d)

```   R = 1     2     3
4     0     2
1     0     0```

14. If one operand is a scalar and the other is not, then MATLAB applies the scalar to every element of the other operand. This property is known as ______________
a) operand divergence
b) scalar expansion
c) vector expansion
d) dimension declaration

15. Matrix operations follow the rules of linear algebra and are not compatible with multidimensional arrays.
a) true
b) false

16. Conversion Function int16 uses_________ range of value?
a) -27 to 27-1
b) -215 to 215-1
c) -231 to 231-1
d) 0 to 216-1

17. Largest and smallest values for integer classes is 127 to -128.
a) True
b) False