Maestro1

ЛР5_1

Jan 6th, 2024
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int m, count_pos, total_pos, d_a_m_i, d_a_m_j, diag_comp;
  8.     float ar_mean, diff_ar_mean;
  9.    
  10.     count_pos=0;
  11.     total_pos= 0;
  12.    
  13.     cout << "Введите размер массива В:" << endl;
  14.     cin >> m;
  15.     int B[m][m];
  16.    
  17.     for(int i = 0; i < m; i++)
  18.     {
  19.         for (int j = 0; j < m; j++)
  20.         {
  21.             cin>>B[i][j];
  22.             if (B[i][j] > 0)
  23.             {
  24.                 count_pos+=1;
  25.                 total_pos+=B[i][j];
  26.             }
  27.         }
  28.     }
  29.    
  30.     ar_mean = total_pos/count_pos;
  31.    
  32.     diff_ar_mean = abs(B[0][0]-ar_mean);
  33.     d_a_m_i = 0;
  34.     d_a_m_j = 0;
  35.    
  36.     for(int i = 0; i < m; i++)
  37.     {
  38.         for (int j = 0; j < m; j++)
  39.         {
  40.             if (abs(B[i][j]-ar_mean) > diff_ar_mean)
  41.             {
  42.                 diff_ar_mean = abs(B[i][j] - ar_mean);
  43.                 d_a_m_i = i;
  44.                 d_a_m_j = j;
  45.             }
  46.         }
  47.     }
  48.    
  49.     diag_comp = 1;
  50.    
  51.     for(int i = 0; i < m; i++)
  52.     {
  53.         for (int j = 0; j < m; j++)
  54.         {
  55.             if ((i == j || i == m-j-1)&& B[i][j] != 0)
  56.             {
  57.                 diag_comp*=B[i][j];
  58.             }
  59.         }
  60.     }
  61.    
  62.     for(int i = 0; i < m; i++)
  63.     {
  64.         for (int j = 0; j < m; j++)
  65.         {
  66.             cout<<B[i][j] << " ";
  67.         }
  68.         cout<< endl;        
  69.     }
  70.  
  71.     cout << "Cреднее арифметическое значение положительных элементов: " << ar_mean << endl;
  72.     cout << "Bндексы элемента, наиболее отличающегося от среднегоарифметического всех элементов равны: " << d_a_m_i << " "<< d_a_m_j << endl;
  73.     cout << "Произведение ненулевых элементов на диагоналях матрицы: " << diag_comp;
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment