Advertisement
istomina_sofia

двумерный массив

Jun 25th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     const int a = 7;
  6.     int array[a][a] = { {6, 0, 0, 1, 9, 4, 0},
  7.                         {6, 0, 0, 1, 9, 4, 0},
  8.                         {6, 0, 0, 1, 9, 4, 0},
  9.                         {6, 0, 0, 1, 9, 4, 0},
  10.                         {6, 0, 0, 1, 9, 4, 0},
  11.                         {6, 0, 0, 1, 9, 4, 0},
  12.                         {6, 0, 0, 1, 9, 4, 0} };
  13.     for (int i = 0; i < a; i++)
  14.     {
  15.         for (int j = 1; j < a; j++)
  16.         {
  17.             int k = j;
  18.             while (array[i][k - 1] == 0 && array[i][k] != 0)
  19.             {
  20.                 int x = array[i][k];
  21.                 array[i][k] = array[i][k - 1];
  22.                 array[i][k - 1] = x;
  23.                 k--;
  24.             }
  25.         }
  26.     }
  27.     for (int i = 0; i < a; i++)
  28.     {
  29.         for (int j = 0; j < a; j++)
  30.         {
  31.             cout << array[i][j] << "";
  32.         }
  33.         cout << endl;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement