Технологии

Найти среднее арифметическое элементов каждого из нечетных столбцов этой матрицы . помогите в C++ срочно пожалуйста. - вопрос №1436496

апрель 3, 2015 г.

  • Всего ответов: 1

  • Виталий - аватарка

    Виталий

    2-й в Технологиях

    #include <iostream>
    #include <vector>

    int main(int argc, char**argv) {
        int rows; int cols;
        std::cout << «Put num rows: »;
        std::cin >> rows;
        std::cout << «Put num cols: »;   
        std::cin >> cols;
        std::cout << «matrix [» << rows << "][" << cols << "]" << std::endl;

        std::vector<std::vector<int> > matrix;
        
        for (int i = 0; i < rows; ++i)
        {
            std::vector<int> tmp;
            for (int j = 0; j < cols; ++j)
            {
                int tmp_i;
                std::cout << «Put matrix element [» << i << "][" << j << "]: ";
                std::cin >> tmp_i;
                tmp.push_back(tmp_i);
            }
            matrix.push_back(tmp);
        }
        std::cout << «Matrix:» << std::endl;
        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < cols; ++j)
            {
                std::cout << (matrix[i])[j] << " ";
            }
             std::cout << std::endl;
        }
        
        for (int i = 0; i < cols; i+=2)
        {
           int summ = 0;
           for (int j = 0; j < rows; ++j)
           {
               summ += (matrix[j])[i];
           }
           float res = (float)summ /(float) rows;
           std::cout << «Result for col » << i << " is " << res << std::endl;
                   
        }
           
        return 0;
    }

    апрель 3, 2015 г.

Похожие вопросы