Answers for "one-dimensional arrays examples c++"

C++
5

2-Dimensional array in c++

int row,col;
cout << "please input how many rows and columns you want accordingly: ";
cin>>row>>col;
//create array in heap.
int **arr=new int*[row];
for(int i=0;i<row;i++)
{
    arr[i]=new int[col];
}
//getting value from user.
for(int i=0;i<row;i++)
{
    for(int j=0;j<col;j++)
    {
        cout<<"Enter a number ";
        cin>>arr[i][j];
    }
}
//display Elements.
    for(int i=0;i<row;i++)
{
    for(int j=0;j<col;j++)
    {
        cout<<arr[i][j]<<" ";
    }
}

return 0;
Posted by: Guest on December-12-2021

Code answers related to "one-dimensional arrays examples c++"

Browse Popular Code Answers by Language