Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- void fillArr(int **arr, int N) {
- for (int i = 0; i < N +15; i++)
- {
- for (int j = 0; j < N+15; j++)
- {
- arr[i][j] = -N + (rand() % ((N + 15) - (-N - 15) + 1));
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- void sortMainDiagnoalArr(int **arr, int N) {
- for (int k = 0; k < N + 15 - 1; k++)
- for (int j = 0; j < N + 15 - k - 1; j++)
- if (arr[j][j] > arr[j + 1][j + 1]) {
- int temp = arr[j][j];
- arr[j][j] = arr[j + 1][j + 1];
- arr[j + 1][j + 1] = temp;
- }
- }
- void displayArr(int **arr, int N) {
- for (int i = 0; i < N + 15; i++)
- {
- for (int j = 0; j < N + 15; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- int main()
- {
- srand(time(0));
- int N;
- cout << "Enter N: ";
- cin >> N;
- int** a = new int*[N+15];
- for (int i = 0; i < N+15; ++i)
- a[i] = new int[N+15];
- fillArr(a, N);
- sortMainDiagnoalArr(a, N);
- cout << endl;
- displayArr(a, N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement