Exercises on Complex Data Types

Time to write some code to solve problems.

Question

Below is a program that uses a struct to encapsulate a two-dimensional matrix. The struct contains the matrix values and the dimensions of the matrix. We assume that the matrix is filled row by row (that is, across columns). Since we haven’t covered dynamic allocation of memory yet, for now, we assume a matrix can hold a maximum number of values equal to 1024. We will cover dynamic allocation of memory later.

Your first task is to write a function that prints a matrix to the screen. A function skeleton is provided (printmat()).

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy