Advertisement
ULK

Лабораторная №9 (12.235(б))

ULK
Jan 17th, 2023
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int m;
  7.     int n;
  8.     int a[100][100];
  9.     int Zero, c;
  10.     int null = 0;
  11.  
  12.     cout << "enter the number of strings: ";
  13.     cin >> m;
  14.  
  15.     cout << "enter the number of columns: ";
  16.     cin >> n;
  17.  
  18.     for (int i = 0; i < m; i++) //заполнение
  19.     {
  20.         for (int j = 0; j < n; j++)
  21.         {
  22.             a[i][j] = rand() % 10;
  23.             cout << a[i][j] << "\t";
  24.         }
  25.         cout << endl;
  26.     }
  27.  
  28.     cout << "enter the amount of zeros: ";
  29.     cin >> Zero;
  30.  
  31.     for (int j = 0; j < n; j++)
  32.     {
  33.         for (int i = 0; i < m; i++)
  34.         {
  35.             if (a[i][j] == 0)
  36.             {
  37.                 null++;         //подсчёт нулей в столбце
  38.             }
  39.         }
  40.  
  41.         if (null == Zero)
  42.         {
  43.             c = j;
  44.             break;
  45.         }
  46.  
  47.         null = 0;
  48.     }
  49.  
  50.     for (int j = c; j < n - 1; j++) //перемещение столбцов
  51.     {
  52.         for (int i = 0; i < m; i++)
  53.         {
  54.             a[i][j] = a[i][j+1];
  55.  
  56.         }
  57.         cout << endl;
  58.  
  59.     }
  60.  
  61.     for (int i = 0; i < m; i++) {
  62.         a[i][n-1] = 0;
  63.     }
  64.  
  65.  
  66.     cout << endl;
  67.  
  68.     for (int i = 0; i < m; i++) //вывод массива 2
  69.     {
  70.         for (int j = 0; j < n; j++)
  71.         {
  72.             cout << a[i][j] << "\t";
  73.         }
  74.         cout << endl;
  75.     }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement