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 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 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) { // Ищем данные по заданию
- float itemssum = 0;
- for (size_t i = 0; i < Rows; i++)
- {
- for (size_t j = 0; j < Columns; j++)
- {
- if (i == j)
- itemssum += Matrix[i][j];
- if (i < j and Matrix[i][j] < 0)
- Matrix[i][j] = abs(Matrix[i][j]);
- }
- }
- Show(Matrix, Rows, Columns);
- cout << "Сумма элементов главной диагонали = " << itemssum << endl;
- }
Add Comment
Please, Sign In to add comment