Write a program which prompts for the number of rows and columns in a 2d matrix
ID: 3656143 • Letter: W
Question
Write a program which prompts for the number of rows and columns in a 2d matrix and then creates the matrix using integers 1,2,3...up to the number of elements. print the matrix then print the sum of the elements of each column in the matrix.
a function prototype should be writing for each function and placed before the main procedure
declare global constant variables storing the max number of rows and max number of columns, both should be set to 50
prompt and read the number of matrix rows and columns
write a function setmatrix() which set the value of elements in the matrix the (i,j)th element of the matrix should have the value i*numcols*j+1 (note that the rows and columns are numbered starting at 0). function should have three parameters; the matrix, #ofrows and number of columns. modifies matrix but returns no value
write a function printmatrix() which prints the elements in the matrix properly formatted into columns and rows. use setw to align the columns. May assume that each matrix entry has at most 3 digits. function should have 3 parameters: matrix, #of rows and #of columns. Does not modify or return a value.
in main program call the first two functions to set and print the matrix
write a function sumcolumn which computes and returns the sum of the elements of each matrix column. Four parameters: column number, matrix, number of rows in matrix and number of columns in the matrix. note that matrix columns are numbered starting at 0.
write a function printcolumnsum() which calls sum_column to compute the sum of each column and print the sum of each column aligned with its column. may assume each sum has at most 4 digits. may have to add space between matrix columns in printmatrix to get appropriate alignment with sums. Function has 3 parameters, matrix, number of rows and number of columns. Does not modify or return a value.
In main program, print line "column sums" call function printcolumnsum to print the column sums.
Don't respond with premade answers; all the ones people keep answering with are not correct at all.
Explanation / Answer
//set matrix corrected #include #include using namespace std; const int MAXROWS=50; const int MAXCOLS=50; void setmatrix(int arr[][MAXCOLS],int row,int col); void printmatrix(int arr[][MAXCOLS],int row,int col); int sumcolumn(int colNum,int arr[][MAXCOLS],int row,int col); void printcolumnsum(int arr[][MAXCOLS],int row,int col); int main(){ int arr[MAXROWS][MAXCOLS]; int rows,cols,i,j,count=0; do{ coutrows; }while(rowsMAXROWS); do{ coutcols; }while(colsMAXCOLS); setmatrix(arr,rows,cols); printmatrix(arr,rows,cols); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.