int n, m, p; //Used as the dimensions of the arrays
cout << "Please enter the number of rows of the first array:" << endl;
cin >> n;
cout << "Please enter the number of columns of the first array:" << endl;
cin >> m;
int**a, **b, **c;
/***********Creating an n*m array**********************/
*a = newint[n];
int dim; //used to traverse the rows of the array
int i; //used to traverse the columns of the array
for(dim=0;dim<n;++m)
a[dim] = newint[m];
/***********Creating an m*p array**********************/
*b = newint[m];
for(dim=0;dim<m;++dim)
b[dim] = newint[p];
/***********Creating an n*p array**********************/
*c = newint[n];
for(dim=0;dim<n;++dim)
c[dim] = newint[p];
/*********reading arrays************/
/********reading array a***********/
for(dim=0;dim<n;++m)
{
cout << "please enter the elements of row " << dim
<<" of array 'A' seperated by spaces:" << endl;
for(i=0;i<m;++i)
cin >> a[dim][i];
}
/********reading array b***********/
for(dim=0;dim<n;++dim)
{
cout << "please enter the elements of row " << dim
<<" of array 'B' seperated by spaces:" << endl;
for(i=0;i<p;++i)
cin >> b[dim][i];
}
cout << "*****Array A**********" ;
for(dim=0;dim<n;dim++)
{
for(i=0;i<p;++i)
cout << a[dim][i];
if( dim == (n-1) )
cout << endl;
}
cout << "*****Array B**********";
for(dim=0;dim<n;dim++)
{
for(i=0;i<p;++i)
cout << a[dim][i];
if( dim == (n-1) )
cout << endl;
}
#include <iostream>
int main()
{
int m, n; //Used as the dimensions of the arrays
std::cout << "Please enter the number of rows of the first array:" << '\n';
std::cin >> m;
std::cout << "Please enter the number of columns of the first array:" << '\n';
std::cin >> n;
int **a;
a = newint *[m];
for(int i = 0; i < m; ++i)
a[i] = newint [n];
for(int i = 0; i < m; ++i)
for(int j = 0; j < n; ++j)
a[i][j] = 1;
for(int i = 0; i < m; ++i)
{
for(int j = 0; j < n; ++j)
std::cout << a[i][j] << ' ';
std::cout << '\n';
}
return 0;
}
Please enter the number of rows of the first array: 6
Please enter the number of columns of the first array: 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 array of pointers to arrays of element (more convenient to use, more cumbersome to create and destroy) 2 1D array indexed as 2D array (this is how a C++ 2D array works)
Condor's response is the first one -- an array of pointers, where each pointer points to an array of elements (in this case, the elements are ints).
cout << "Please enter the number of columns of the first array:" << endl;
cin >> m;
cout << "Please enter the number of columns of the second array:" << endl;
cin >> p;
int **a, **b, **c;
/***********Creating an n*m array**********************/
a = newint *[n];
int dim=0; //used to traverse the rows of the array
int i=0; //used to traverse the columns of the array
for(dim=0;dim<n;++m)
a[dim] = newint[m];
/********reading array a***********/
for(dim=0;dim<n;++m)
{
cout << "please enter the elements of row " << dim
<<" of array 'A' seperated by spaces:" << endl;
for(i=0;i<m;++i)
cin >> a[dim][i];
}