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?
3 Réponses
+ 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.
+ 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
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.