DasShelmer

6.3.19

Oct 15th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6.     setlocale(LC_ALL, "Russian");
  7.  
  8.     int i, j, n, max, min, maxIndx;
  9.     cout << "Введите размер массива n: ";
  10.     cin >> n;
  11.     int** arr = new int* [n];
  12.     for (i = 0; i < n; i++)
  13.         arr[i] = new int[n];
  14.  
  15.     // Простое заполнение массива
  16.     for (i = 0; i < n; i++)
  17.         for (j = 0; j < n; j++)
  18.             arr[i][j] = i * 10 + j;
  19.     // Обработка элементов
  20.     for (i = 0; i < n; i++) {
  21.         max = arr[i][0];
  22.         min = max;
  23.         maxIndx = 0;
  24.         for (j = 0; j < n; j++) {
  25.             if (arr[i][j] > max) {
  26.                 max = arr[i][j];
  27.                 maxIndx = j;
  28.             }
  29.             if (arr[i][j] < min) {
  30.                 min = arr[i][j];
  31.             }
  32.         }
  33.         arr[i][maxIndx] = min;
  34.     }
  35.     // Вывод массива
  36.     for (i = 0; i < n; i++) {
  37.         for (j = 0; j < n; j++)
  38.             cout << setw(4) << setprecision(2) << arr[i][j] << " ";
  39.         cout << endl;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment