Hi everyone. I have two matrices that are input by the user. My question is how would I count the number of border elements that are zero in the FIRST matrix only? Any ideas? I know I will need some for loops, etc.
Okay, I've come up with an idea to do this. I'm going to add up the first and last rows and columns, then subtract the corners. I going to use an if statement making the size at least 3x3 so the matrix will have some interior. Here's the function I have so far. The first part is correct (rows), but the second part (columns) is what I'm having trouble with. How do I get a for loop to just go down instead of across? Any ideas?
I'm not exactly sure what you mean. I'm not sure how to find the sum of the first and last columns. I'm sure there is some error in my second for loop, but I'm not exactly sure what it is.
This is what I have now. I'm not sure if I'm supposed to put two elements inside brackets, but it seems logical. Still wrong output though. I could really use some help with this.
PSEUDOCODE
sum = 0
for first row and last row:
for each column:
sum += is element equal to zero?
for all rows except first and last:
sum += is first column equal to zero?
sum += is last column equal to zero?
Don't take this too hard, but at some point you are going to have to use your brain on this. I'm not just going to give you code. (Though I've all but done that already.)
So if you know how many items there are, how do you loop through all but the first and last?
I know that, and I'm really trying. I wouldn't post anything on here unless I truly needed help because I've tried everything I know. What I was asking is, can you do a for loop with two specifications as you indicated above. I've never done that or seen, thus I don't know how. That is why I asked the question.