• В матрице А(5,6) найти среднее арифметическое отрицательных элементов каждого столбца в С++ .

Ответы 1

  • #include <iostream>

    #include <iterator>

    #include <vector>

     

    using namespace std;

     

    int main() {

     int n = 5;

     int m = 6;

     

     vector<vector<int>> a(n, vector<int>(m));

     

     for (int i = 0; i < n; ++i) {

       for (int j = 0; j < m; ++j)

         cin >> a[i][j];

     }

     

     vector<double> ans(m);

     

     for (int i = 0, q = 0; i < m; ++i, ++q) {

       int sum = 0;

       int cnt = 0;

     

       for (int j = 0; j < n; ++j) {

         if (a[j][i] < 0) {

           sum += a[j][i];

           ++cnt;

         }

       }

     

       if (sum)

         ans[q] = sum / (double)cnt;

     }

     

     copy(ans.cbegin(), ans.cend(), ostream_iterator<double>(cout, " "));

    }

    • Автор:

      aylin
    • 5 лет назад
    • 0
  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years