GarikK

Сортировка строк в двухмерном массиве

Mar 13th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. // Rjadkii.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. using namespace std;
  8. int main()
  9. {
  10.     srand(time(NULL));
  11.     int array[5][5];//creating array
  12.     for (int i = 0; i < 5; i++)
  13.     {
  14.         for (int j = 0; j < 5; j++)
  15.         {
  16.             array[i][j] = rand() % 10;//input random digits into array
  17.         }
  18.     }
  19.     //sorting every row in array from min to max
  20.     for (int x = 0; x < 5; x++)
  21.     {
  22.         for (int i = 0; i < 5; i++)
  23.         {
  24.             for (int j = 0; j < 5 - 1; j++)
  25.             {
  26.                 if (array[i][j] > array[i][j + 1])
  27.                 {
  28.                     int tmp = array[i][j];
  29.                     array[i][j] = array[i][j + 1];
  30.                     array[i][j + 1] = tmp;
  31.                 }
  32.             }
  33.         }
  34.     }
  35.     //showing sorted array
  36.     for (int i = 0; i < 5; i++)
  37.     {
  38.         for (int j = 0; j < 5; j++)
  39.         {
  40.             cout << array[i][j] << " ";
  41.         }
  42.         cout << endl;
  43.     }
  44.  
  45. }
Add Comment
Please, Sign In to add comment