Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double-subscripted array - sum for each column

Status
Not open for further replies.

chevere

Technical User
Sep 10, 2004
10
US
Does someone know how to get the sum for each column in a double subscripted array? I know how to get the sum for each row.
 
int values[ROWS][COLS];

if this is what you mean, it is just the reverse of the row sum

int rowSum = 0;
for(int col = 0;col<COLS;col++)
{
rowSum += values[rowToSum][col];
}

for columns it would be

for(int row = 0;row<ROWS;row++)
{
colSum += values[row][colToSum];
}

Matt
 
Hey thanks... I will try this evening... I understand your concept...

chevere
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top