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 perevorot(int** matr, int n, int m){
- int r, a = 0, b = 0;
- while (b < m){
- if (b % 2 == 1){
- while (a < n / 2){
- r = matr[a][b];
- matr[a][b] = matr[n - 1 - a][b];
- matr[n - 1 - a][b] = r;
- a++;
- }
- }
- a = 0;
- b++;
- }
- cout << "После обработки строк :" << endl;
- r = 0;
- a = 0;
- while (r < m){
- while (a < n){
- cout << setw(6) << matr[a][r] << " ";
- a++;
- }
- a = 0;
- cout << endl;
- r++;
- }
- }
- void main()
- {
- int stolb, strok, i = 0, j = 0;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во столбцов в двумерном массиве" << endl;
- cin >> stolb;
- cout << "Введите кол-во строк в двумерном массиве" << endl;
- cin >> strok;
- time_t t;
- srand((unsigned)time(&t));
- int** matr = form_matr(stolb, strok);
- while (j < strok){
- while (i < stolb){
- cout << setw(6) << matr[i][j] << " ";
- i++;
- }
- i = 0;
- cout << endl;
- j++;
- }
- perevorot(matr, stolb, strok);
- }
Advertisement
Add Comment
Please, Sign In to add comment