How would I write a nested for statement that initializes each element of the array t[2][5] to zero?
Also how do I display the elements of the first row of array t[2][5]?
Thank you.
How would I write a nested for statement that initializes each element of the array t[2][5] to zero?
Also how do I display the elements of the first row of array t[2][5]?
Thank you.
How do you think you'd do it? Give me a break! TRY IT ON YOUR OWN FIRST!
Break it down in logical steps. for each row for each colum set this value to that value. It's not hard. Give it a try eh?
Quzah. :very very very mad:
is this right?:
for (row = 0; row <=2; row++)
t[row][5] = 0;
for (column = 0; column <=5, column++)
t[2][column] = 0;
im still tryin to figure out the part about printing the elements of the first row.
sorry to have ........ed ya off to hell like that.
It's not you exclusively. Every day, people show up and say "do my homework plz", without even trying it on their own. There is a FAQ at this site, there's also a link, right at the very very top, that says "READ THIS FIRST", and yet, noone ever reads it. That's what ........es me off.
I don't mind helping people (actually I enjoy it, otherwise I wouldn't be here) who make an attempt at trying something.
Ok, think of an array as a grid. (Or a line, if you've just got a single dimension array). As such, how would you count or use the elements in the array, one at a time? Well, you'd start at zero and work your way up.
You need two loops here, if you're doing a single cell at a time.
One increments the row, and one increments the column.
Thus, you start at row0 and go up through row(N-1).
The same goes for columns. colum0 through column(N-1).
Where N is the max size of your array.
Thus, if we have an array 6 blocks long, we start at zero, and to up through 5. This means we can use a loop like this:
for( row = 0; row < 6; row++ )
You can do the same for columns. Then you end up changing the value at that spot, which something like this:
array[row][column] = 0;
That help? I've given you enough to go on, but not the whole code.
Quzah.
so would this work forl array t[2][5]?
for (row=0, row < 2, row++)
for (column=0, column < 5, column++)
t[row][column]=0;
Well, did it work? Slap that sucker in a block of code, and try it out. Yes, it should work, assuming you declared your variables first and what not.
Quzah.
I was just cruising around the board in search of something interesting since i have absolutely nothing to do right now. And i stumbled upon these Homework posts Quazh is so understandably upset about, just looking over them made me a little angry.
How can someone ask "would this work?"? If you have a compiler you can answer that question yourself ALL too EASILY. If it doens't work THEN you post and ask "WHY doesn't this work?".
If you ask for someone to help before you actually try to do something, it's just like asking them to do it for you. Programming is all about doing stuff on your own, if you never try to do anything you'll never get stuck, and more often than not it's when you get stuck that you actually learn the important lessons. Programming is about solving problems, solving problems is about using you brain.
In closing: First use your brain, then IF/WHEN you get stuck ask for help, and all the people here wíll be more than happy to help you. I know I will, and i think so will Quazh.
adios,
biterman.
PS: It also helps to actually ponder HARD on the problem that has you stuck -until you're at your wits end-, if you still can't figure it out then when someone explains it to you it feels much better. Like a HUGE load of your back.
Do you know how contemptous they are of you?
amen
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
If you can't say anything nice, then just keep your damn mouth shut. Just because you may be somewhat of an expert, doesn't mean you put down everyone else. If you don't like what they posted or what they asked for, then just move on. *Deleted*
Now now. There are some valid points here, you do at least appear to be breaking board rules.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Take it easy guys, I think that Quzah said it all.
And yes,
AMEN
No it wont. Look closely at your for statements.Then look closely at Quzah's and you will see the difference.so would this work forl array t[2][5]?
for (row=0, row < 2, row++)
for (column=0, column < 5, column++)
t[row][column]=0;
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
yeah i know i put , instead of ; i always do that stupid mistake.
Was that directed at me? I read my reply a couple times again looking for the part that wasn't nice. I failed to find it.If you can't say anything nice, then just keep your damn mouth shut. Just because you may be somewhat of an expert, doesn't mean you put down everyone else. If you don't like what they posted or what they asked for, then just move on. *Deleted*
adios,
biterman.
Do you know how contemptous they are of you?