Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <locale>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- // Все нечетные строки матрицы сдвинуть циклически на К элементов влево.
- int* form_mas(int count){
- int* massive = new int[count];
- int a = 0;
- while (a < count){
- massive[a] = rand() % 500 - 150;
- a++;
- }
- return massive;
- }
- int** form_matr(int n, int m)
- {
- int **matr = new int*[n];//выделение памяти под массив указателей
- for (int i = 0; i < n; i++){
- //выделение памяти 100*sizeof(int) байт для массива значений
- matr[i] = form_mas(m);
- }
- return matr;//возвращаем указатель на массив указателей
- }
- void Sort(int** matr, int i, int j){
- int r, a = 0,k=0,M,n;
- cout << "Введите число сдвигов : ";
- cin >> M;
- // Перестановка
- while (a < j){
- if (a % 2 == 1){
- for (n = 0; n < M; n++)
- {
- r = matr[0][a];
- for (int i = 0; i < j - 1; i++)
- matr[i][a] = matr[i + 1][a];
- matr[j - 1][a] = r;
- }
- }
- a++;
- }
- cout << "После обработки строк :" << endl;
- r = 0;
- a = 0;
- while (r < j){
- while (a < i){
- cout << setw(6) << matr[a][r] << " ";
- a++;
- }
- a = 0;
- cout << endl;
- r++;
- }
- }
- void main()
- {
- int n, m, i = 0, j = 0;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во столбцов в двумерном массиве" << endl;
- cin >> n;
- cout << "Введите кол-во строк в двумерном массиве" << endl;
- cin >> m;
- time_t t;
- srand((unsigned)time(&t));
- int** matr = form_matr(n, m);
- while (j < m){
- while (i < n){
- cout << matr[i][j] << " ";
- i++;
- }
- i = 0;
- cout << endl;
- j++;
- }
- Sort(matr, n, m);
- }
Advertisement
Add Comment
Please, Sign In to add comment