/* This program demonstrates * 2 dimensional dynamic arrays * * A 2 dimensional dynamic array is organized as a single dimensional array of * pointers, each of which points to a single "row" of the array - a single * dimensional array. * * This needs a 2-level pointer to access it. It also needs to be created and deleted * in 2 steps. * * We need to be sure we are within the bounds of the dynamic array. */ #include using namespace std; /* If we have a dynamic 2D array, we use a 2-level pointer, whether * it is as a parameter or as a return type */ int ** twoDArrayDemo(int rows, int columns); int matrixSearch(int ** arr, int r, int cN, int val); int main() { int r,c; cout<<"Enter the number of rows and columns: "; cin>>r>>c; // We need a 2-level pointer to point to a 2D dynamic array int ** mat = twoDArrayDemo(r,c); cout<<"The matrix is : \n"; for(int i=0; i>searchCol; cout<<"Enter the value to search: "; cin>>val; int found = matrixSearch(mat,r,searchCol,val); cout<<"Value was found in row "<< found; // delete the 2D array // first, delete each individual row for(int i=0; i> mat[i][j]; } /* The max norm of a matrix is the largest balue in th ematrix */ int maxNorm = mat[0][0]; for(int i=0; i maxNorm) maxNorm = mat[i][j]; } } cout<<"The max norm is "<< maxNorm<