Advertisement
Lisaveta777

Anna 1

Apr 20th, 2022
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     setlocale(LC_ALL, "Russian");
  10.  
  11.     srand(time(0));
  12.  
  13.     int m, n;
  14.  
  15.     m = 3; n = 4;
  16.     int** arr = new int* [m]; //Делает массив случайным
  17.     for (int i(0); i < m; i++)
  18.         arr[i] = new int[n];
  19.  
  20.     cout << "Случайный массив A: " << endl;
  21.  
  22.     for (int i = 0; i < m; i++)
  23.     {
  24.         for (int j = 0; j < n; j++)
  25.         {
  26.             arr[i][j] = rand() % 21 - 5; // Массив выводит числа от -5 до 15
  27.             cout << arr[i][j] << " ";
  28.         }
  29.         cout << endl;
  30.     }
  31.  
  32.     cout << endl;
  33.  
  34.     m = 4; n = 5;
  35.     int** yrr = new int* [m];
  36.     for (int i(0); i < m; i++)
  37.         yrr[i] = new int[n];
  38.  
  39.     cout << "Случайный массив Y: " << endl;
  40.  
  41.     for (int i = 0; i < m; i++)
  42.     {
  43.         for (int j = 0; j < n; j++)
  44.         {
  45.             yrr[i][j] = rand() % 21 - 5;
  46.             cout << yrr[i][j] << " ";
  47.         }
  48.         cout << endl;
  49.     }
  50.  
  51.     cout << endl;
  52.  
  53.  
  54.     cout << "Средне геометрическое массива:" << endl;
  55.  
  56.     int scet, nescet, h;
  57.     scet = 0, nescet = 0, m = 4; n = 5, h = 0;
  58.  
  59.     //Цикл в котором все положительные числа строк умножаются, считается количество множителей
  60.  
  61.     for (int i = 0; i < m; i++)
  62.     {
  63.         for (int j = 0; j < n; j++)
  64.         {
  65.             if (arr[i][j] > 0)
  66.             {
  67.                 scet = scet * arr[i][j];
  68.                 h++;
  69.             }
  70.  
  71.             if (yrr[i][j] > 0)
  72.             {
  73.                 scet = scet * yrr[i][j];
  74.                 h++;
  75.             }
  76.         }
  77.  
  78.         if (scet > 0)
  79.         {
  80.             scet = pow(scet, 1 / h); //должно считаться средне арефметическое
  81.         }
  82.  
  83.         cout << scet << endl;
  84.  
  85.         scet = 0;
  86.     }
  87.     return 0;
  88. }// То, что  я последнее делала позавчера я не сохранила, есть только документ с первыми тремя попытками, так что решила переписать его уже заново и добавить вместо сложения это средне геометрическое, но все равно не получается....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement