Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
0
Добавлен:
16.06.2026
Размер:
15.63 Кб
Скачать

6. Написать функцию для нахождения произведения чисел для каждого столбца двумерного

#include <iostream>

void findProductOfColumns(int** matrix, int numRows, int numCols) {

if (numRows <= 0 || numCols <= 0) {

std::cout << "Invalid matrix dimensions." << std::endl;

return;

}

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

int product = 1;

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

product *= matrix[i][j];

}

std::cout << "Product of column " << j + 1 << ": " << product << std::endl;

}

}

int main() {

int numRows, numCols;

std::cout << "Enter the number of rows: ";

std::cin >> numRows;

std::cout << "Enter the number of columns: ";

std::cin >> numCols;

// Выделение памяти под двумерный массив

int** matrix = new int*[numRows];

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

matrix[i] = new int[numCols];

}

std::cout << "Enter the elements of the matrix:" << std::endl;

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

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

std::cin >> matrix[i][j];

}

}

findProductOfColumns(matrix, numRows, numCols);

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

delete[] matrix[i];

}

delete[] matrix;

return 0;

}

Соседние файлы в папке Двумерные динамические Массивы ( Решение)