#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