Advertisement
hurmawe

lab2 alg

Nov 18th, 2022
559
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 1 0
  1. #include <iostream>
  2. #include <random>
  3. #include<iomanip>
  4. using namespace std;
  5.  
  6. void main()
  7. {
  8.     setlocale(LC_ALL, "Russian");
  9.     srand(time(0));
  10.     int array[8][5];
  11.     int max = INT_MIN;
  12.     int min = INT_MAX;
  13.     int max_s = 0;
  14.     int max_s_a = INT_MIN;
  15.     int number_s = 0;
  16.     for (int i = 0; i < 8; i++)
  17.     {
  18.         for (int j = 0; j < 5; j++)
  19.         {
  20.             array[i][j] = rand() % 20 - 10;
  21.             cout << setw(3) << array[i][j] << " ";
  22.             if (max < array[i][j]) max = array[i][j];
  23.             if (min > array[i][j]) min = array[i][j];
  24.             max_s = array[i][j];
  25.         }
  26.         if (max_s_a < max_s)
  27.         {
  28.             max_s_a = max_s;
  29.             number_s = i;
  30.         }
  31.         max_s = 0;
  32.         cout << endl;
  33.     }
  34.     cout<<"Максимальное число: " << max << endl;
  35.     cout << "Минимальное число: " << min << endl;
  36.     cout << "Строка " << number_s+1 << ": ";
  37.     for (int i = 0; i < 5; i++)
  38.     {
  39.         cout << array[number_s][i] << " ";
  40.     }
  41.     cout << endl;
  42.  
  43.     int column;
  44.     int line;
  45.     cout << "Введите количество столбов: ";
  46.     cin >> column;
  47.     cout << "Введите количество строк: ";
  48.     cin >> line;
  49.  
  50.     int** array_din = new int*[column];
  51.     for (int i = 0; i < column; i++)
  52.         array_din[i] = new int [line];
  53.  
  54.    
  55.     max = INT_MIN;
  56.     min = INT_MAX;
  57.     max_s = 0;
  58.     max_s_a = INT_MIN;
  59.     number_s = 0;
  60.     for (int i = 0; i < column; i++)
  61.     {
  62.         for (int j = 0; j < line; j++)
  63.         {
  64.             array_din[i][j] = rand() % 20 - 10;
  65.             cout << setw(3) << array_din[i][j] << " ";
  66.             if (max < array_din[i][j]) max = array_din[i][j];
  67.             if (min > array_din[i][j]) min = array_din[i][j];
  68.             max_s = array_din[i][j];
  69.         }
  70.         if (max_s_a < max_s)
  71.         {
  72.             max_s_a = max_s;
  73.             number_s = i;
  74.         }
  75.         max_s = 0;
  76.         cout << endl;
  77.     }
  78.     cout << "Максимальное число: " << max << endl;
  79.     cout << "Минимальное число: " << min << endl;
  80.     cout << "Максимальная строка " << number_s + 1 << ": ";
  81.     for (int i = 0; i < line; i++)
  82.     {
  83.         cout << array_din[number_s][i] << " ";
  84.     }
  85.  
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement