#include <iostream>
using namespace std;
class Dynamic{
};
int main()
{
  int rows , cols, x = 0;
 cout<<"Insert the dimensions of the array\n";
  cout<<"Enter the rows of the 2D array\n";
  cin>>rows;
  cout<<"Enter the columns of the 2D array\n";
  cin>>cols;
  int** arr = new int*[rows];
Â
  for (int i = 0; i < rows; i++) {
Â
    Â
    arr[i] = new int[cols];
  }
cout<<"Insert the elements of the 2D array"<<endl;
cout<<" Press -1 to stop inserting elements\n";
 Â
 for(int i=0; i<rows; i++){
 for(int j=0; j<cols; j++){
 cin>>arr[i][j];
 if(arr[i][j] == -1){
 break; }Â
}
x++;
break;
}
  int arr1[rows][cols];
  for(int i=0; i<rows; i++){
  for(int j=0; j<cols; j++ ){
  arr1[i][j] = arr[i][j];
 Â
  }
  delete [] arr[i];
  }
  cout<<"The array contains the elements\n";
  Â
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      cout << arr1[i][j] << " ";
    }
    cout << endl;
  } Â
   Â
   delete [] arr;      Â
  cout<<"Enter the elements of the 2D array to be deleted"<<endl;
cout<<" Press -1 to stop \n";
for(int i=0; i<rows; i++){
  for(int j=0; j<cols; j++){
 cin>>arr1[i][j];
 if(arr1[i][j] == -1){
 break; }
}
x++;
break;}
}
Comments
Leave a comment