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 Show1DIM(int*, size_t);
- void NewMassGen(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);
- NewMassGen(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"; // Выводим введенный массив
- }
- void Show1DIM(int* Matrix, size_t Columns) {
- cout << "\nПолученный массив:" << endl;
- for (size_t i = 0; i < Columns; i++)
- cout << Matrix[i] << "\t"; // Выводим полученный массив
- }
- void Kill(int** Matrix, size_t Rows) {
- for (size_t i = 0; i < Rows; i++)
- delete[] Matrix[i];
- delete[] Matrix;
- }
- void NewMassGen(int** Matrix, size_t Rows, size_t Columns) { // Ищем данные по заданию
- int elsum, max_in_row, * TaskArray;
- elsum = 0;
- if (Rows >= Columns)
- TaskArray = new int[Columns]();
- else
- TaskArray = new int[Rows]();
- for (size_t i = 0; i < Rows; i++)
- {
- max_in_row = Matrix[i][i];
- for (size_t j = 0; j < Columns; j++)
- {
- if (Matrix[i][j] > max_in_row)
- max_in_row = Matrix[i][j];
- elsum += Matrix[i][j];
- }
- if (Matrix[i][i] == max_in_row) {
- TaskArray[i] = 1;
- }
- }
- if (Rows >= Columns)
- Show1DIM(TaskArray, Columns);
- else
- Show1DIM(TaskArray, Rows);
- cout << "\n\nСумма элементов матрицы = " << elsum << endl;
- delete[] TaskArray;
- }
Add Comment
Please, Sign In to add comment