Advertisement
ULK

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

ULK
Jan 17th, 2023 (edited)
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 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 summ, c;
  10.     int sum = 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.             sum += a[i][j];
  25.         }
  26.  
  27.         cout << "sum of the string: " << sum;
  28.         cout << endl;
  29.         sum = 0;
  30.     }
  31.  
  32.     cout << "enter the sum for comparison: ";
  33.     cin >> summ;
  34.  
  35.     for (int i = 0; i < m; i++) //сравнение с заданным числом
  36.     {
  37.         for (int j = 0; j < n; j++)
  38.         {
  39.             sum += a[i][j];
  40.         }
  41.  
  42.         if (sum < summ)
  43.         {
  44.             c = i;
  45.             break;
  46.         }
  47.  
  48.         sum = 0;
  49.     }
  50.  
  51.     for (int i = c; i < m - 1; i++) //перемещение строк
  52.     {
  53.         for (int j = 0; j < n; j++)
  54.         {
  55.             a[i][j] = a[i + 1][j];
  56.  
  57.         }
  58.         cout << endl;
  59.  
  60.     }
  61.  
  62.     for (int j = 0; j < n; j++) { //обнуление последней строки
  63.         a[m - 1][j] = 0;
  64.     }
  65.  
  66.  
  67.     cout << endl;
  68.  
  69.     for (int i = 0; i < m; i++) //вывод массива 2
  70.     {
  71.         for (int j = 0; j < n; j++)
  72.         {
  73.             cout << a[i][j] << "\t";
  74.         }
  75.         cout << endl;
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement