|
-
January 16th, 2013, 12:45 PM
#11
Re: I need very fast help, like within the hour, please!
If I understand the problem correctly, you have one matrix, A[4][7]. So, it's 4 rows and 7 columns. You need to then add the numbers starting at the third column going through the 7th column for each column correct?
Consider a similar problem. You have to add all the numbers in column 3 and 4 together. For this problem, it's probably easier to do this a row at a time. You start with the first row. Grab the numbers starting at the third column and go to the last column. Then, you bump your row index up to the second row, etc. Consider the following matrix:
Code:
1 2 3 4
5 6 7 9
3 2 5 6
That is a 3 X 4 matrix, lets call it Matrix.
If I wanted to get the sum of all the numbers in the last two columns I would first initialize some counter to zero. I would start at the 3rd element in the above array from the first row, or Matrix[0][2]. I would add this onto the counter, then move onto the next element in the row, or Matrix[0][3]. At this point, I've run out of numbers in the row, so I need to jump down to the second row and start over, or to Matrix[1][2].
But this isn't quite what your assignment is asking you to do. It looks like it wants you to add all the positive numbers from columns 3,4,5,6, and 7. So, instead of moving to the right in the above example, you need to move down, so you'll need to access Matrix[0][2], Matrix[1][2], and so forth. Once you get to the forth row Matrix[3][2], you'll now have your sum for that column. There's an additional requirement that the numbers you sum be positive, but that shouldn't be too difficult.
The code for this assignment is not very difficult, and if you find yourself writing a bunch of code, you are probably doing something wrong.
Last edited by Alterah; January 16th, 2013 at 12:49 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|