Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <conio.h>
- #include <ctime>
- using namespace std;
- int main() {
- setlocale(LC_ALL , "Russian");
- int n;
- cout << "Введите количество строк: ";
- cin >> n;
- int ** a = new int * [n];
- for (int i = 0; i < n; i++) { //Создается массив
- a[i] = new int[n];
- }
- srand(time(NULL));
- for (int i = 0; i < n; i++) { //Массив заполняется случайными числами
- for (int j = 0; j < n; j++) {
- a[i][j] = rand() % n + 1;
- }
- }
- for (int i = 0; i < n; i++) { //Вывод массива на экран
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << '\t';
- }
- cout << endl;
- }
- system("pause");
- cout << endl;
- for (int g = 0; g < n; g++) { //Массив сортирует числа в каждой строке от большего к меньшему
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n-1; j++) {
- if (a[g][j] < a[g][j+1]) {
- swap(a[g][j], a[g][j+1]);
- }
- }
- }
- }
- for (int i = 0; i < n; i++) { //Вывод массива на экран
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << '\t';
- }
- cout << endl;
- }
- system("pause");
- cout << endl;
- for (int g = 0; g < n; g++) { //Массив сортируется по первому столбцу от меньшего к большему
- for (int i = 0; i < n-1; i++) {
- if (a[i][0] > a[i+1][0]){
- swap(a[i], a[i+1]);
- }
- }
- }
- for (int i = 0; i < n; i++) { //Вывод массива на экран
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << '\t';
- }
- cout << endl;
- }
- system("pause");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement