Matrix

This is a discussion on Matrix within the C++ Programming forums, part of the General Programming Boards category; Does anyone know how to get this program to output 4 rows and 3 columns of numbers? Code: #include <iostream> ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    10

    Matrix

    Does anyone know how to get this program to output 4 rows and 3 columns of numbers?

    Code:
     
    #include <iostream> 
    #include <iomanip>
    
    using namespace std;
    
    
    int main()
    {
        int matrix[4][3];
    
                                          
        
        int j, k;
    
        for (j = 0; j < 4; j++)
        {
            for (k = 0; k < 3; k++)
                matrix[j][k] = 2 * j + k;
                cout << matrix[j][k] << " ";
    
            cout << endl;
        }
    }

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    you're missing brackets for the inner for loop:
    Code:
        for (j = 0; j < 4; j++)
        {
            for (k = 0; k < 3; k++)
            {
                matrix[j][k] = 2 * j + k;
                cout << matrix[j][k] << " ";
            }
            cout << endl;
        }
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Continued here sorry wrong code apparently.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 02:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 07:36 AM

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