This may be all you need -
Approach 1: Using a simple 2-D array
#include <iostream>
using namespace std;
int main()
{
int dimension1, dimension2 = 5;
cout << "Enter first dimension : " << endl;
cin >> dimension1;
// dynamic allocation
int** array2d = new int*[dimension1];
for(int i = 0; i < dimension1; ++i)
array2d[i] = new int[dimension2];
/*
// you may fill it with your values
for(int i = 0; i < dimension1; ++i)
for(int j = 0; j < dimension2; ++j)
array2d[i][j] = i;
*/
// print
for(int i = 0; i < dimension1; ++i) {
for(int j = 0; j < dimension2; ++j) {
cout << array2d[i][j] << " ";
}
cout << endl;
}
// free
for(int i = 0; i < dimension1; ++i)
delete [] array2d[i];
delete [] array2d;
return 0;
}
Sample Output :
Enter first dimension :
4
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Approach 2: Using Vectors -
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// size of row
int rowSize;
int colSize = 5;
cout << "Enter row size : ";
cin >> rowSize;
// Create a vector of vector with size equal to rowSize; filled with 0.
vector<vector<int>> vec(rowSize, vector<int>(colSize));
for (int i = 0; i < rowSize; i++) {
for (int j = 0; j < vec[i].size(); j++)
cout << vec[i][j] << " ";
cout << endl;
}
vec.clear();
return 0;
}
Sample Output :
Enter row size : 3
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0