Matrices with Full Storage
Functions dealing with matrices
Complete the following code snippet such that:
-
function initMatrix initializes a matrix row-wise with \(1\), \(2\), \(\dots\)
-
function printMatrix prints the content of a matrix.
#include <stddef.h> #include <stdio.h> void initMatrix(size_t m, size_t n, double *A, ptrdiff_t incRow, ptrdiff_t incCol) { // your code here } // your code for function printMatrix here #define MAX_ROWS 100 #define MAX_COLS 100 double A[MAX_ROWS*MAX_COLS]; int main() { size_t m = 5; size_t n = 8; size_t incRow = n; size_t incCol = 1; initMatrix(m, n, A, incRow, incCol); printMatrix(m, n, A, incRow, incCol); // make additions here: return 0; }
Using Functions
Make additions to function main (and only main) such that:
-
matrix \(A\) gets initialized column-wise with \(1\), \(2\), \(\dots\) and its content printed.
-
print the second row of \(A\)
-
print the third column of \(A\)
-
init the sub-matrix \(A(2:3, 3:6)\) row-wise with \(1\), \(2\), \dots
-
print the complete matrix