fork download
  1. #include <iostream>
  2. #include <time.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. srand(time(NULL));
  8. const int n = 6;
  9. int matr[n][n];
  10.  
  11. for (int i = 0; i < n; ++i) {
  12. for (int j = 0; j < n; j++) {
  13. matr[i][j] = rand() %
  14. 100;//Заполняем массив случайными числами до 100
  15. cout << matr[i][j] << "\t|\t"; //Вывод на экран
  16. }
  17.  
  18. cout << endl;
  19. }
  20.  
  21. for (int i = 0; i < n; ++i) {
  22. //Вибираем четные элементы побочной диагонали матрицы
  23. if (matr[i][n - 1 - i] % 2 == 0) {
  24. sort(&matr[i][0], &matr[i][0] + n);
  25. }
  26. }
  27.  
  28. cout << endl << "Отсортированная матрица: " << endl;
  29.  
  30. for (int i = 0; i < n; i++) {
  31. for (int j = 0; j < n; j++) {
  32. cout << matr[i][j] << "\t|\t"; //вывод на экран новой марицы
  33. }
  34.  
  35. cout << endl;
  36. }
  37. }
  38.  
Success #stdin #stdout 0.01s 5388KB
stdin
Standard input is empty
stdout
54	|	59	|	35	|	95	|	68	|	75	|	
67	|	42	|	68	|	79	|	77	|	19	|	
27	|	79	|	30	|	15	|	68	|	34	|	
19	|	61	|	82	|	94	|	23	|	30	|	
61	|	98	|	49	|	84	|	34	|	80	|	
12	|	88	|	39	|	47	|	35	|	59	|	

Отсортированная матрица: 
54	|	59	|	35	|	95	|	68	|	75	|	
67	|	42	|	68	|	79	|	77	|	19	|	
27	|	79	|	30	|	15	|	68	|	34	|	
19	|	23	|	30	|	61	|	82	|	94	|	
34	|	49	|	61	|	80	|	84	|	98	|	
12	|	35	|	39	|	47	|	59	|	88	|