After running this code , it will generate a random array of desired rows and columns . Then a loop will divide the array by its diagonal into an upper side and lower side.In the upper side the loop will look for a `max number` and in the lower side the loop will look for a `min number` . Then in the final stage I need to change the positions of `min` and `max` . `Max` in place of `min` and vice versa.The code runs and finds the `min` and `max`.Don't know how to change their places.

> 
> Code
> 
> 
> 

```
#include <iostream>
#include <time.h>
#include <limits.h>

using namespace std;

int main(){
int rows, columns;
int max = INT_MAX;
int min = INT_MIN;
int XindexOfMax, YindexOfMax;
int XindexOfMin, YindexOfMin;

cout << "Enter rows: ";
cin >> rows;
cout << "Enter columns: ";
cin >> columns;

int **array = new int *[rows];            //generating random array
for(int i = 0; i < rows; i++)
    array[i] = new int[columns];

srand((unsigned int)time(NULL));         //generating randoms

for(int i = 0; i < rows; i++){           //loop for the main array
    for(int j = 0; j < columns; j++){
        array[i][j] = rand() % 10;    
        cout << array[i][j] << " "; 
    }
    cout << "\n";
}

cout << "For finding Max: " << endl;

for(int i = 0; i < rows; i++){             //upper half of the diagonal
    for(int j = 0; j < columns - i; j++){
        cout << array[i][j] << " ";
        if(array[i][j] > max){
            max = array[i][j];
            XindexOfMax = i;              //find x and y coordinates if max
            YindexOfMax = j;
        }

    }
    cout << "\n";
}
cout << "For finding Min: " << endl;

for (int i = 0; i < rows; i++){          // lower half of the diagonal
    for (int j = 0; j < columns; j++){
        if (j < columns - i - 1){
            cout << "  ";
        }
        else{
            cout << array[i][j] << " "; 
            if(array[i][j] < min){
                min = array[i][j];
                XindexOfMin = i;       //find x and y coordinates if min
                YindexOfMin = j;
            }
        }
    }
cout << "\n";
}
cout << "Result" << endl;
//swapping positions of min and max 
std::swap(array[XindexOfMax][YindexOfMax], array[XindexOfMin][YindexOfMin]);

for(int i = 0; i < rows; i++){        
    for(int j = 0; j < columns; j++){
        cout << array[i][j] << " ";   //Printing the final array
    }
    cout << "\n";
}
return 0;
}

```