c# - Finding the column total in an array -
i have 1-dimensional array random elements, got through m*n grid. want find out row total , column total, present in it.
here how 1 dimensional array is: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
i want treat :
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
now want find reo total , column total. row total done follows:
for (int = 0; < totalrows; i++) { (int j = 0; j < totalcolumns; j++) { rowtotal[i] += numbers[temp + j]; } temp += totalcolumns; }
i trying same column. here code:
for (int = 0; < totalcolumns; i++) { tempk = 0; (int j = 0; j < totalrows; j++) { blocktotal[i] += numbers[i+j+tempk]; tempk += totalcolumns; } }
am not able column total, intended. please help.
you can both in same loop
for (int = 0; < totalrows; i++) { (int j = 0; j < totalcolumns; j++) { rowtotal[i] += numbers[i * totalcolumns + j]; blocktotal[j] += numbers[i * totalcolumns + j]; } }
Comments
Post a Comment