give me example array two dimension

my teacher told me about array two dimension , but i can't understand at all
maybe somebody can give me example,

nb: i am using programmer notepad
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
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
 
int main()
{
    const int M = 3;
    const int N = 5;
    const int MAX_VALUE = 100;
 
    int a[M][N];
 
    std::srand( std::time( 0 ) );
 
    for ( auto &row : a )
    {
        for ( auto &x : row ) x = std::rand() % MAX_VALUE;
    }
 
    for ( const auto &row : a )
    {
        for ( auto x : row ) std::cout << std::setw( 2 ) << x << ' ';
        std::cout << std::endl;
    }
 
    return 0;
}
Last edited on
Don't be surprised if you cannot compile Vlad's code: it uses C++11 range-based for() loops.

http://cplusplus.com/doc/tutorial/arrays/#multidimensional_arrays
i remember my teacher tell me only about
#include<cstdlib>
#Include<iostream>
using namespace std;
int main ()
like this program
#include<cstdlib>
#include<iostream>
using namespace std;
int main ()
{
int billy []={1,2,3,4,5};
int n, result=0;
for (n=0;n<5;n++)
{
result += billy [n];
}
cout<<result;
system("PAUSE");
return 0;
}

but i need another example

#sorry for double posting
http://www.cplusplus.com/doc/tutorial/arrays/

look towards the bottom of that link.


google is your friend.
can you give me another example of array 2 dimension
1
2
int a[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
int b[2][3] = {};
Topic archived. No new replies allowed.