cavaman

2.29

May 25th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. #include<Windows.h>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);//русский
  13.     srand(time(NULL));
  14.  
  15.     int n, m, x;
  16.     cout << "Введите количество строк" << "\n";
  17.     cin >> n;
  18.     m = 2 * n; //столбцы
  19.     cout << "Введите X" << "\n";
  20.     cin >> x;    
  21.    
  22.     // динамическое создание двумерного массива
  23.     int** A = new int* [n]; // строк в массиве
  24.     for (int i = 0; i < n; i++)
  25.         A[i] = new int[m]; // столбцов
  26.    
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         for (int j = 0; j < m; j++)
  30.         {
  31.             A[i][j] = rand() % 100;
  32.             cout << setw(3) << A[i][j] << ' ';
  33.         }
  34.         cout << "\n";
  35.     }
  36.    
  37.     // Массив b
  38.     int* b= new int[n];
  39.  
  40.     for (int i = 0; i < n; i++)
  41.     {        
  42.         if (A[i][0]<=x)
  43.             b[i] = 1;
  44.         else
  45.             b[i] = 0;
  46.     }
  47.     for (int i = 0; i < n; i++)
  48.     {
  49.         cout << b[i] << " ";
  50.     }
  51.  
  52.     // Удаление массива
  53.     for (int i = 0; i < n; i++)
  54.     {
  55.         delete[]A[i];
  56.     }
  57.     delete[] A;
  58.     delete[] b;
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment