Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #array
ADD COMMENT
Topic
Name
8+2 =