Apr 10, 2013 at 11:15am Apr 10, 2013 at 11:15am UTC
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
Apr 10, 2013 at 11:24am Apr 10, 2013 at 11:24am UTC
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 Apr 10, 2013 at 11:25am Apr 10, 2013 at 11:25am UTC
Apr 10, 2013 at 1:25pm Apr 10, 2013 at 1:25pm UTC
i remember my teacher tell me only about
#include<cstdlib>
#Include<iostream>
using namespace std;
int main ()
Apr 10, 2013 at 1:26pm Apr 10, 2013 at 1:26pm UTC
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
Apr 10, 2013 at 10:44pm Apr 10, 2013 at 10:44pm UTC
can you give me another example of array 2 dimension