Lecture 22 – Nov 1st, 2019

2. $cp -r ~steve/ex/mda . Task 1. Implement the function read_array in array.c. It should read in a rectangular (2D) array of integers from the specified file into an array and return the array along with the number of rows and columns. See array.h and array.c for details. The first line of the file contains two integers: the number of rows and the number of columns. Following this are number-of-rows lines each of which contains number-of-columns integers. For example, 5 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 represents a 2D array with 5 rows and 3 columns (this file is in small.txt) $\begin{pmatrix}1&2&3\\4&5&6\\7&8&9\\10&11&12\\13&14&15\end{pmatrix}.$ 2. Implement the function write_array in array.c. It should first write out the number of rows and then columns on the line followed by the data of the array to the file. 3. Test that your code works by making copyarray ($ make copyarray) and then trying to copy the array from small.txt into copy.txt.
The transpose of the small $5\times 3$ array above is the $3\times 5$ array $\begin{pmatrix}1&4&7&10&13\\2&5&8&11&14\\3&6&9&12&15\end{pmatrix}.$
Note that if you have a $k\times m$ matrix and a $m\times n$ matrix, then the result of multiplication is a $k\times n$ matrix. Otherwise, the multiplication isn’t defined.