Sum of row - matrix

Hey!
I have problem with finding the sum of first row.
ex.

1 2 3 = 6
4 5 6 = 15
7 8 9 = 24

Tnx for the help! :))
Please show us the code you have so far, and we will see if we can help.
I've done the sum of all the rows and colomns
1
2
3
4
5
6
7
8
9
for (i = 0; i < m; i++) {
for (j = 0; j <n; j++) {

sum1 = v[0][j];
sum2 = v[i][0];
}
}

cout<<sum1<<", "<<sum2<<endl;


But I don't know how to get the sum of each row and column.
Last edited on
This is what you are after:

1
2
rowSum += v[i][j];
columnSum += v[j][i];    // Note the transposed index values. 


You need to reset the sums back to 0 for each interation of "i", and you want to print the sums for each iteration of "i". (You'll need a couple lines of code between the fors and between the closing braces of the loops.)
Topic archived. No new replies allowed.