# Lab 8 – 2017

Slides: [ EST ] [ ENG ]
Homework II generator: [ Link ]

Homework:

1p – Correct solution
1p – Considering at least 2 edge cases

• The arrays should be at least 4 x 4
• Display also the starting arrays (square matrices) for all the solutions
• Based on the last digit of your matricular number pick a task from the following:
1. Output only every other element in the array
2. Multiply every element with some number (e.g. “4”)
3. Replace the elements in the main and anti-diagonal (wiki link) with “X”
4. Transpose the matrix (array) (replace rows and columns)
5. Subtract the sum of numbers under the main diagonal from the sum of numbers above the diagonal
6. Display a N-size multiplication table
7. Display statistics about the matrix (positive and negative nr.s)
1. Output the number of positive/negative numbers and what are they
8. Sort matrix by rows
9. Sort matrix by columns
10. Output sum(row) – sum(col) for all of the rows and columns

Example solutions with the following array:

``` 8 -3  6
-6  5  2
-9  0 -7```
1. ` 8 6 -6 2 -9 -7`
2. ```32  -12  24
-24  20  8
-36  0  -28```
3. ``` X -3  X
-6  X  2
X  0  X```
4. ``` 8 -6 -9
-3  5  0
6  2 -7```
5. `(-3 + 6 + 2)-(-6+ -9 + 0) = 20`
6. N is 3
```1 2 3
2 4 6
3 6 9```
7. ```5 positive numbers: 8, 6, 5, 2, 0
4 negative numbers: -3, -6, -9, -7```
8. ```-3  8  6
-6  2  5
-9 -7  0```
9. ```-9 -3 -7
-6  0  2
8  5  6```
10. ```(8 + -3 + 6) - (8 + -6 + -9) = 18
(-6 + 5 + 2) - (-3 + 5 + 0) = -1
(-9 + 0 + -7) - (6 + 2 + -7) = 17```