0

Hey i have a c++ question, so how would you create a program that computes the sums of rows and columns of a square matrix?...

You would have to use a multi dimensional array right?

23rd Aug 2017, 2:15 AM
Raad Wassey
3 Respostas
+ 1
It can be done with one dimensional array but from mathematical point of view you need 2D array. One dimensional arrays are faster. Use two for loops one inside the other to iterate through rows/columns.
23rd Aug 2017, 6:03 AM
Grzegorz Skryty
Grzegorz Skryty - avatar
+ 1
It actually doesn't matter but I'm going to describe 2D method first. It can be done with two double for loop: int row = 5; // number of rows int column = 5;. // number of columns int scolumn[row] = {0,};. // array with column sums int arr[row][column] = {{0,}, {0,}}; // code for reading text file here for(int i = 0; i < row; i++) { for(int j = 0; j < column; j++) { scolumn[i] += arr[i][j]; } } the second double for loop try write on yourself
23rd Aug 2017, 11:48 PM
Grzegorz Skryty
Grzegorz Skryty - avatar
0
Thanks for the clarification, but it would have to read the matrix from a text file, add them and then output. This part is really confusing.
23rd Aug 2017, 4:53 PM
Raad Wassey