Advertisement
cacodemon665

Лаба 5 Вариант 3

Nov 27th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <limits.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. { //create array
  9.     int rows;
  10.     int cols;
  11.     cout << "Input rows & cols: ";
  12.     cin >> rows >> cols;
  13.     int **arr = new int*[rows];
  14.     for (int i = 0; i < rows; i++)
  15.     {
  16.         arr[i] = new int[cols];
  17.     }
  18.     //filling array
  19.     cout << endl;
  20.     cout << "fill the array: " << endl;
  21.     for (int i = 0; i < rows; i++)
  22.     {
  23.         for (int j = 0; j < cols; j++)
  24.         {
  25.             cout << "[" << i << "]" << "[" << j << "]: ";
  26.             cin >> arr[i][j];
  27.             cout << endl;
  28.         }
  29.     }
  30.     //show the array
  31.     for (int i = 0; i < rows; i++)
  32.     {
  33.         for (int j = 0; j < cols; j++)
  34.         {
  35.             cout << arr[i][j] << " ";
  36.         }
  37.         cout << endl;
  38.     }
  39.     //code
  40.     int *bool_arr = new int[rows];
  41.     for (int i = 0; i < rows; i++)
  42.     {
  43.         int k = 0;
  44.         int s = cols - 1;
  45.         while (k < cols / 2)
  46.         {
  47.             if (arr[i][k] == arr[i][s])
  48.             {
  49.                 bool_arr[i] = 1;
  50.             }
  51.             else { bool_arr[i] = 0; }
  52.             k++;
  53.             s--;
  54.         }
  55.     }
  56.     cout << endl;
  57.     for (int i = 0; i < rows; i++)
  58.     {
  59.         cout << bool_arr[i] << " ";
  60.     }
  61.  
  62.     delete[] bool_arr;
  63.  
  64.     //delete array
  65.     for (int i = 0; i < rows; i++)
  66.     {
  67.         delete[] arr[i];
  68.     }
  69.  
  70.     delete[] arr;
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement