Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int m, count_pos, total_pos, d_a_m_i, d_a_m_j, diag_comp;
- float ar_mean, diff_ar_mean;
- count_pos=0;
- total_pos= 0;
- cout << "Введите размер массива В:" << endl;
- cin >> m;
- int B[m][m];
- for(int i = 0; i < m; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cin>>B[i][j];
- if (B[i][j] > 0)
- {
- count_pos+=1;
- total_pos+=B[i][j];
- }
- }
- }
- ar_mean = total_pos/count_pos;
- diff_ar_mean = abs(B[0][0]-ar_mean);
- d_a_m_i = 0;
- d_a_m_j = 0;
- for(int i = 0; i < m; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (abs(B[i][j]-ar_mean) > diff_ar_mean)
- {
- diff_ar_mean = abs(B[i][j] - ar_mean);
- d_a_m_i = i;
- d_a_m_j = j;
- }
- }
- }
- diag_comp = 1;
- for(int i = 0; i < m; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if ((i == j || i == m-j-1)&& B[i][j] != 0)
- {
- diag_comp*=B[i][j];
- }
- }
- }
- for(int i = 0; i < m; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout<<B[i][j] << " ";
- }
- cout<< endl;
- }
- cout << "Cреднее арифметическое значение положительных элементов: " << ar_mean << endl;
- cout << "Bндексы элемента, наиболее отличающегося от среднегоарифметического всех элементов равны: " << d_a_m_i << " "<< d_a_m_j << endl;
- cout << "Произведение ненулевых элементов на диагоналях матрицы: " << diag_comp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment