Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <iostream>
- using namespace std;
- int** CreateMatrix(int**, size_t, size_t);
- void Show(int**, size_t, size_t);
- void CountNegativeEl(int**, size_t, size_t);
- void Kill(int**, size_t);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int** Matrix = NULL;
- size_t Rows, Columns;
- cout << "Введите кол-во строк: ";
- cin >> Rows;
- cout << "Введите кол-во столбцов: ";
- cin >> Columns;
- Matrix = CreateMatrix(Matrix, Rows, Columns);
- Show(Matrix, Rows, Columns);
- CountNegativeEl(Matrix, Rows, Columns);
- Kill(Matrix, Rows);
- return 0;
- }
- int** CreateMatrix(int** Matrix, size_t Rows, size_t Columns) { // Создание матрицы
- Matrix = new int* [Rows];
- cout << "\nЗаполните массив:\n";
- for (size_t i = 0; i < Rows; i++) // Указатель i
- {
- Matrix[i] = new int[Columns]; // Выделяем память
- for (size_t j = 0; j < Columns; j++) // Цикл, заполняющий массив / указатель j
- {
- cout << "Массив [" << i + 1 << "][" << j + 1 << "] = "; // Показываем, какой элемент сейчас вводим
- cin >> Matrix[i][j]; // Вводим этот элемент
- }
- }
- return Matrix;
- }
- void Show(int** Matrix, size_t Rows, size_t Columns) { // Выводим введенный массив
- cout << "\nВведенный массив:" << endl;
- for (size_t i = 0; i < Rows; i++, cout << endl)
- for (size_t j = 0; j < Columns; j++)
- cout << Matrix[i][j] << "\t";
- cout << endl;
- }
- void Kill(int** Matrix, size_t Rows) { // Очищаем память
- for (size_t i = 0; i < Rows; i++)
- delete[] Matrix[i];
- delete[] Matrix;
- }
- void CountNegativeEl(int** Matrix, size_t Rows, size_t Columns) { // Ищем данные по заданию
- int quant, quant_in_row, quantquant;
- quant = 0; // Количество неотр. эл. во всей матрице
- quantquant = 0; // Значения этих элементов
- for (size_t i = 0; i < Rows; i++)
- {
- quant_in_row = 0; // Количество неотр. элементов в ряду
- for (size_t j = 0; j < Columns; j++)
- {
- if (Matrix[i][j] >= 0) {
- quantquant += Matrix[i][j];
- quant++;
- quant_in_row++;
- }
- }
- cout << "В " << i + 1 << " строке " << quant_in_row << " неотриц. эл.\n";
- }
- cout << "\nСреднее арифметическое неотриц. элементов матрицы = " << quantquant / quant << endl;
- }
Add Comment
Please, Sign In to add comment