2d Array

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 2
Reputation: iorisendoh is an unknown quantity at this point 
Solved Threads: 0
iorisendoh iorisendoh is offline Offline
Newbie Poster

2d Array

 
-1
  #1
Sep 27th, 2004
hi can someone help how to make a program or exampel of program using two dimensional array. Or can someone help me to make program by this problem >Write a program using two dimensional array that searches a number and display the of times it occurs on the list of twelve input value.
I'm asking for help coz my Prof. didn't explain it very well
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: 2d Array

 
0
  #2
Sep 27th, 2004
Greetings,

Using a 2-Dimensional array isn't very difficult at all. In fact for simplicity, lets take a look how a 2-Dimensional array looks in all aspects.

int myValue[2][3];

We know this array is going to be a 2x3 rectangle. So lets see how this looks:

  1. Rows/Columns Column 0 Column 1 Column 2 Column 3
  2. Row 0 myValue[0][0] myValue[0][1] myValue[0][2] myValue[0][3]
  3. Row 1 myValue[1][0] myValue[1][1] myValue[1][2] myValue[1][3]

Not bad at all. How about if we initialize this array:

int myValue[2][3] = { {5, -3, 0}, {10, 17, -25} };

There are two blocks, with 3 numbers inside each initializing our 2x3 array completlely:

  1. Rows/Columns Column 0 Column 1 Column 2
  2. Row 0 5 -3 0
  3. Row 1 10 17 -25

This should all be making sense. To set your array's data outside of the initilization isn't hard at all:

int main() {
	int myValue[2][3]

	myValue[0][0] = 5;
	myValue[0][1] = -3;
	myValue[0][2] = 0;

	myValue[1][0] = 10;
	myValue[1][1] = 17;
	myValue[1][2] = -25;

	return 0;
}

So think of a 2-Dimensional array as a rectangle. Rows and Columns, right and down. Once you have this down, please feel free to ask more questions.


- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 2
Reputation: hamsa is an unknown quantity at this point 
Solved Threads: 0
hamsa hamsa is offline Offline
Newbie Poster

Re: 2d Array

 
0
  #3
Nov 5th, 2004
sorry this my question
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 76343 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC