I have to write a program that would generate a matrix that should display the following output. They are asking that we dont hard code our values in this program. I am lost on how I will get these values to display without hard coding. My question is how should my expression look. Any information that you all can give me I would greatly appreciate it.
Instead of storing the values in an array, consider how you could compute each value from the loop index variables at the position you need to print it. For example, 2, 4, 6... could be (column + 1)*2, right? If you think a little about it, there's a pretty obvious equation that uses both "row" and "column" and computes the value of every cell in your matrix.
I suspect it's OK to hardcode the "5"'s, by the way -- the loop limits.
Yes I see the pattern, for every number in the first row you add 2 then the next row you add 3 to each number then so on and so on. I know am missing something on trying to put this all into one equation. Am going to take a break and then come back and look at it again. To try to find what am missing.
hmmm... what can i use to easily get me those numbers, one after the other...
HEY!!! that kind of sounds like a for-loop might work. I can start my loop with any value i want, so starting it at 2 shouldn't be a problem. then, I just have to make sure I stop it before my counter gets to be 7.
subject: 2 dimensional array without hard coding values