- 1

how to find sum of column of a 2d array in c++?

to find sum of all columns of array

9th Jul 2017, 3:48 AM
real kurama
real kurama - avatar
4 Respuestas
+ 1
1 8 9 6 7 2 7 3 8 having the 2 dimenssion array int [][] a = new int[3][3]; a[0][0] = 1; a[0][1] = 8; a[0][2] = 3; a[1][0] = 6; a[1][1]; a[1][2]; a[2][0] = 7; a[2][1] = 3; a[2][2] = 8; for (int i = 0; i < 4; i ++){ for (int j = 0; j < 4;j++){ if (i == 1){ sum = sum + a[i][j]; } } This is an example to calculate the sum of the second column.
9th Jul 2017, 4:13 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
+ 1
yes, just remove the if condition
9th Jul 2017, 7:56 AM
Claudiu Stefan Haidu
Claudiu Stefan Haidu - avatar
0
cant we find sum of all columns without finding sum of indivivual columns?
9th Jul 2017, 4:20 AM
real kurama
real kurama - avatar
0
thanks
9th Jul 2017, 7:59 AM
real kurama
real kurama - avatar