Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. void fillArr(int **arr, int N) {
  7. for (int i = 0; i < N +15; i++)
  8. {
  9. for (int j = 0; j < N+15; j++)
  10. {
  11. arr[i][j] = -N + (rand() % ((N + 15) - (-N - 15) + 1));
  12. cout << arr[i][j] << " ";
  13. }
  14. cout << endl;
  15. }
  16. }
  17. void sortMainDiagnoalArr(int **arr, int N) {
  18. for (int k = 0; k < N + 15 - 1; k++)
  19. for (int j = 0; j < N + 15 - k - 1; j++)
  20. if (arr[j][j] > arr[j + 1][j + 1]) {
  21. int temp = arr[j][j];
  22. arr[j][j] = arr[j + 1][j + 1];
  23. arr[j + 1][j + 1] = temp;
  24. }
  25. }
  26. void displayArr(int **arr, int N) {
  27. for (int i = 0; i < N + 15; i++)
  28. {
  29. for (int j = 0; j < N + 15; j++)
  30. {
  31. cout << arr[i][j] << " ";
  32. }
  33. cout << endl;
  34. }
  35. }
  36. int main()
  37. {
  38. srand(time(0));
  39. int N;
  40. cout << "Enter N: ";
  41. cin >> N;
  42. int** a = new int*[N+15];
  43. for (int i = 0; i < N+15; ++i)
  44. a[i] = new int[N+15];
  45. fillArr(a, N);
  46. sortMainDiagnoalArr(a, N);
  47. cout << endl;
  48. displayArr(a, N);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement