printing two dimensional array

This is a discussion on printing two dimensional array within the C++ Programming forums, part of the General Programming Boards category; I have a matrix and I need to be able to print out all of its contents. Right now I ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    27

    printing two dimensional array

    I have a matrix and I need to be able to print out all of its contents. Right now I have it such that const int size = 2;
    And then my matrix is matrix[size][size];

    It needs to work of course so that if I change the size it will still work properly. I know I need to do it using to for loops and two variable row and column. But I have been thinking about it for a couple hours and I can't come up with anything. Can anybody help?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    It needs to work of course so that if I change the size it will still work properly. I know I need to do it using to for loops and two variable row and column.
    Wouldnt it be something as simple as:
    Code:
    for (int i = 0; i < size; ++i) {
    	for (int j = 0; j < size; ++j) {
    		// print matrix[i][j]
    	}
    	// print a break (e.g. newline) for next row of matrix
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scanf confusion, 2 dimensional array modification
    By Leojeen in forum C Programming
    Replies: 23
    Last Post: 10-19-2008, 10:58 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21