Well, you have a row index and a column index (call them i and j respectively), and you know the number of rows and the number of columns. For the left side, the elements to the left of the diagonal are the ones you are interested in and those are defined as those array elements where the row index is greater than the column index. For the right side of the diagonal, you are interested in those elements where the row index is less than the column index. So you're going to have a nested loop:
for (int i = ?; i < ?; i++) // rows
{
for (int j = ?; ? < ?; j++)
{
// add element (i,j) to the sum
}
}
Fill in the question marks for the correct loop parameters. These question marks will depend on whether you are doing the left or right side. Note the elements you are interested in above and design your loops so that all of those index combinations and only those index combinations go through the loop.
Last edited by VernonDozier; May 5th, 2008 at 12:10 am.
Reputation Points: 2614
Solved Threads: 687
Posting Expert
Offline 5,372 posts
since Jan 2008