Can anyone help me with this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

11th Feb 2021, 12:23 PM
aecliam
aecliam - avatar
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.
11th Feb 2021, 1:37 PM
Shadow
Shadow - avatar
+ 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
11th Feb 2021, 1:06 PM
Shadow
Shadow - avatar
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
11th Feb 2021, 1:18 PM
aecliam
aecliam - avatar
0
Thanks so much! It worked!
11th Feb 2021, 2:06 PM
aecliam
aecliam - avatar