Write a program which prompts for the number of rows and columns in a 2D matrix
ID: 3655659 • Letter: W
Question
Write a program which prompts for the number of rows and columns in a 2D matrix and then creates a matrix containing integers 1, 2, 3, : : : up to the number of matrix elements. Print the matrix and then print the sum of the elements of each column in the matrix. 1) Declare GLOBAL constant variables storing the maximum number of rows and maxi mum number of columns. Both of these should be set to 50. 2) Prompt and read the number of matrix rows and number of matrix columns. Note that the matrix should be allocated to have size (max num rows) by (max num columns). Only a subset of those rows and columns are used. 3) Write a function set_matrix() which sets the value of the elements of the matrix. The (i, j)'th element of the matrix should have value i*num_cols+j+1. (Note that the rows and columns are numbered starting at 0.) The function should take three parameters, the matrix, the number of rows in the matrix and the number of columns in the matrix. Note that the matrix argument has size (max num rows) by (max num columns). The function modifies the matrix but does not return any value. 4) Write a function print_matrix() which prints the elements of the matrix, properly formatted in rows and columns. Use setw from the iomanip library to align the columns. You may assume that each matrix entry has at most 3 digits. The function should take three parameters, the matrix, the number of rows in the matrix and the number of columns in the matrix. The function does not modify the matrix or return any value. 5). In the main program, call the functions set_matrix and then print_matrix to set and print the matrix. 6). Write a function sum_column which computes and returns the sum of the elements of a matrix column. The function should take four parameters, the column number, the matrix, the number of rows in the matrix and the number of columns in the matrix. Note that matrix columns are numbered starting at 0. The function returns the sum of the elements of a matrix column. 7). Write a function print_column_sum which calls sum_column to compute the sum of each column and prints the sum of each column, aligned with its column. You may assume that each sum has at most 4 digits. You may have to add space between matrix columns in print_matrix() to get the appropriate alignment with the column sums. The function should take three parameters, the matrix, the number of rows in the matrix and the number of columns in the matrix. The function does not modify the matrix or return any value. 8). In the main program, print the line Column sums:". Call function print_column_sum to print the column sums.Explanation / Answer
#include #include #define rowSIZE 5 #define colSIZE 5 int myMatrix[rowSIZE][colSIZE]; int myFunction(void) { int row = 0, col = 0; for (row = 0; rowRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.