Advertisement
alexdmin

7.3

Apr 12th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main(int argc, const char* argv[]) {
  9.     srand(time(NULL));
  10.     setlocale(LC_ALL, "rus");
  11.     int m, n;
  12.     cout << "Введите кол-во строк n: ";
  13.     cin >> n;
  14.     cout << "Введите кол-во столбцов m: ";
  15.     cin >> m;
  16.  
  17.     int u = 0;
  18.     cout << "1 - описывая двумерный массив как указатель на массив указателей\n2 - описывая двумерный массив как одномерный, с расчётом смещения элемента массива по линейной формуле\n";
  19.     cin >> u;
  20.     switch (u)
  21.     {
  22.     case 1:
  23.     {
  24.         int** ptrarray;
  25.         ptrarray = new int* [n];
  26.         for (int i_row = 0; i_row < n; i_row++) {
  27.             ptrarray[i_row] = new int[m];
  28.         }
  29.  
  30.  
  31.         cout << "Введите массив:" << endl;
  32.         for (int i_row = 0; i_row < n; i_row++) {
  33.             for (int j_column = 0; j_column < m; j_column++) {
  34.                 cin >> ptrarray[i_row][j_column];
  35.             }
  36.  
  37.  
  38.         }
  39.         for (int i_row = 0; i_row < n; i_row++) {
  40.             for (int j_column = 0; j_column < m; j_column++)
  41.                 cout << setw(2) << ptrarray[i_row][j_column] << "   ";
  42.             cout << endl;
  43.         }
  44.         cout << endl;
  45.         int maxstolb, maxstrok;
  46.         int maxMult = 0;
  47.  
  48.  
  49.  
  50.         maxMult = 0;
  51.         for (int j = 0; j < n; j++)
  52.         {
  53.             int tempM = 1;
  54.             for (int i = 0; i < m; i++)
  55.             {
  56.                 tempM *= ptrarray[i][j];
  57.             }
  58.             if (maxMult < tempM) { maxstolb = j; maxMult = tempM; }
  59.         }
  60.  
  61.  
  62.         cout << "Максимальное произведение в столбике " << maxstolb + 1 << " = " << maxMult << endl;
  63.  
  64.  
  65.  
  66.         for (int k = 0; k < n; k++)
  67.             delete[]ptrarray[k];
  68.         delete[]ptrarray;
  69.  
  70.         break;
  71.     }
  72.     case 2:
  73.     {
  74.         int** ptrarray = new int* [n];
  75.         for (int i = 0; i < n; i++) {
  76.             ptrarray[i] = new int[n];
  77.         }
  78.         cout << "Введите массив:" << endl;
  79.         for (int i_row = 0; i_row < n; i_row++) {
  80.             for (int j_column = 0; j_column < m; j_column++) {
  81.                 cin >> ptrarray[i_row][j_column];
  82.             }
  83.  
  84.  
  85.         }
  86.         for (int i_row = 0; i_row < n; i_row++) {
  87.             for (int j_column = 0; j_column < m; j_column++)
  88.                 cout << setw(2) << ptrarray[i_row][j_column] << "   ";
  89.             cout << endl;
  90.         }
  91.         cout << endl;
  92.         int maxstolb, maxstrok;
  93.         int maxMult = 0;
  94.  
  95.  
  96.  
  97.         maxMult = 0;
  98.         for (int j = 0; j < n; j++)
  99.         {
  100.             int tempM = 1;
  101.             for (int i = 0; i < m; i++)
  102.             {
  103.                 tempM *= ptrarray[i][j];
  104.             }
  105.             if (maxMult < tempM) { maxstolb = j; maxMult = tempM; }
  106.         }
  107.  
  108.  
  109.         cout << "Максимальное произведение в столбике " << maxstolb + 1 << " = " << maxMult << endl;
  110.         delete[]ptrarray;
  111.     }
  112.  
  113.     }
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement