0
Can anyone help me with this?
This is the supposed output: Enter number of rows: 2 Enter number of columns: 2 Element [0][0]: 5 Element [0][1]: 4 Element[1][0]: 2 Element[1][1]: 1 The table matrix is: 5 4 2 1 The sum of column 1 is: 7 The sum of column 2 is: 5 The difference of column 1 is: 3 The difference of column 2 is: 3 The product of column 1 is: 10 The product of column 2 is: 4 The quotient of column 1 is: 2 The quotient of column 2 is: 4
4 Answers
+ 1
You can just initialize "dcol" and "qcol" before the nested loop with the first value of the column, i.e.
dcol = arr[ 0 ][ b ];
and then start iteration at the second value. Also, "pcol" should be (re-)set to 1, not 0, otherwise the product will always be 0.
+ 1
Since the number of rows/ columns is unknown at compile time, dynamic memory allocation should be used. You can either allocate a single block for 'rows' * 'columns' elements, which would later require translation from two-dimensional indices to one-dimensional indices, or you could allocate memory for 'rows' pointers which then each allocate memory for 'columns' elements (pointer to pointer).
Afterwards, it is just a matter of iterating the matrix, usually done with a nested loop (one for the rows, one for the columns). For the calculations, you can use variables to store the temporary results while iterating a column.
That should be enough to get you started. If you need further help, you should post what you have coded so far for examination, and explain where you are stuck.
Also, if you want to study similar codes, there are some on the playground, e.g.
https://code.sololearn.com/cy4NxiEY4X9t/?ref=app
https://code.sololearn.com/c6hi86GeSeRG/?ref=app
https://code.sololearn.com/ca1A19A12a17/?ref=app
0
This is my progress so far. Iâm having trouble with the answers in difference to quotation.
https://code.sololearn.com/cStQsJWtxU26/?ref=app
0
Thanks so much! It worked!