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;
- while (k < i){
- for (int i = 1; i < j; i++)
- for (int a = j - 1; a >= i; a--)
- if (matr[k][a] > matr[k][a - 1])
- {
- int r = matr[k][a];
- matr[k][a] = matr[k][a - 1];
- matr[k][a - 1] = r;
- }
- k++;
- }
- 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