954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C Arrays

hello guys:
i awais ahmad has a simple problem with the two dimensional array.
that is how to get two values in one column of the array

Awais Ahmad
Newbie Poster
5 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Sometimes when English isn't your native language it is even more difficult to explain what you want to do than it is for us native English speakers. To use multidiminsional arrays you can do something like this:

int array[2][2];

which declares a variable on the stack with enough memory for 4 ints. Now to get the information into that array you can do several things. Here's one way:

for(int i = 0; i < 2; ++i)
{
  for(int j = 0; j < 2; ++i)
 {
     cout <<"enter a value" << endl;
     cin >> array[i][j];
  }
}

and to dispay the values you use another nested loop except the body would be something like:

//pseudocode to display array as a table
for()
  for()
     cout << array[i][j] << ' ';  
  cout << endl;
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You