Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cppstudio.com - обучайся здесь
- #include <iostream>
- #include <Windows.h>
- #include <cstdlib>
- int** AllocMatrix(int row_count,int column_count)
- {
- int** newMatrix = new int*[row_count];
- for (int i = 0; i < row_count; i++)
- newMatrix[i] = new int[column_count];
- for (int i = 0; i < row_count; i++)
- for (int j = 0; j < column_count; j++)
- newMatrix[i][j]=-45+rand()%121;
- return newMatrix;
- }
- void ShowMatrix(int** matrix, int row_count, int column_count)
- {
- for (int i = 0; i < row_count; i++)
- {
- for (int j = 0; j < column_count; j++)
- {
- std::cout.width(5);
- std::cout << matrix[i][j];
- }
- std::cout << std::endl;
- }
- }
- /*Добавляет элемент в одномерный массив
- arr - текущий одномерный массив
- previous_size -текущий размер массива
- value - добавляемое значение в массив
- */
- void AppendToArr(int*& arr, int &previous_size,int value)
- {
- int* copyArr = new int[previous_size + 1];
- for (int i = 0; i < previous_size; i++)
- copyArr[i] = arr[i];
- copyArr[previous_size] = value;
- delete[] arr;
- arr = copyArr;
- previous_size++;
- }
- int* CreateArrayFromWay(int** matrix, int row_count, int column_count, int& newArraySize)
- {
- if (row_count != column_count || row_count == 0 && column_count)
- {
- std::cout << "Ошибка неверный размер";
- return nullptr;
- }
- newArraySize = 0;
- int leftIndex = 0;
- int rightIndex = column_count-1;
- int downIndex = row_count - 1;
- int upIndex = 0;
- int* newArr = new int[0];
- }
- int main(int agrc, char* argv[])
- {
- int n;
- int* newArray = nullptr;;
- int** currentMatrix=nullptr;
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- std::cout << "n=";
- std::cin >> n;
- currentMatrix = AllocMatrix(n, n);
- std::cout << "Матрица" << std::endl;
- ShowMatrix(currentMatrix,n,n);
- /*std::cout << "-----------------" << std::endl;
- std::cout << "Массив:" << std::endl;*/
- int iCount = 0;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement