how to print a matrix of 3x3

Hello , I have studied the arrays section here. Now I am trying to print a matrix .Can anyone please tell me how to print it ?
I assume with printing you mean print on the screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace std;

int matrix[3][3];

int main()
{
    // asigning values, I suppose this is done allready.

    for(int x=0;x<3;x++)
    {
        for(int y=0;y<3;y++)
        {
            matrix[x][y]=1;
        }
    }

    // showing the matrix on the screen

    for(int x=0;x<3;x++)  // loop 3 times for three lines
    {
        for(int y=0;y<3;y++)  // loop for the three elements on the line
        {
            cout<<matrix[x][y];  // display the current element out of the array
        }
    cout<<endl;  // when the inner loop is done, go to a new line
    }
    return 0;  // return 0 to the OS.
}


this should show a matrix on the screen in a simple console application.

regards, Ronnie van Aarle.
Thank you Ronnie !
Topic archived. No new replies allowed.