Advertisement
mr1302

ad

Feb 22nd, 2021
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <time.h>
  5.  
  6. using namespace std;
  7.  
  8. bool symmetry(vector<vector<int>>& a) {
  9.     if (a.size() == 1) return true;
  10.     for (int i = 1; i < a.size(); ++i)
  11.         for (int j = 0; j < i; ++j) {
  12.             if (a[i][j] != a[j][i])
  13.                 return false;
  14.             cout << j << '\n';
  15.         }
  16.     return true;
  17. }
  18.  
  19. void fill_keyb(vector<vector<int>>& a) {
  20.     for (int i = 0; i < a.size(); ++i) {
  21.         for (int j = 0; j < a.size(); ++j) {
  22.             int x = 0;
  23.             cin >> x;
  24.             a[i][j] = x;
  25.         }
  26.     }
  27. }
  28.  
  29. void fill_rand(vector<vector<int>>& a) {
  30.     for (int i = 0; i < a.size(); ++i)
  31.         for (int j = 0; j < a.size(); ++j)
  32.             a[i][j] = rand() % 100;
  33.     cout << "Полученная матрица:\n";
  34.     for (int i = 0; i < a.size(); ++i) {
  35.         for (int j = 0; j < a.size(); ++j)
  36.             cout << a[i][j] << " ";
  37.         cout << '\n';
  38.     }
  39. }
  40.  
  41. int main() {
  42.     srand(time(0));
  43.     setlocale(LC_ALL, "Rus");
  44.     cout << "Введите размер матрицы\n";
  45.     int size = 0;
  46.     cin >> size;
  47.     vector<vector<int>> a(size, vector<int> (size, 0));
  48.     cout << "Ввести элементы матрицы с клавиатуры (1) или заполнить случайными числами (0)?\n";
  49.     int temp = 0;
  50.     cin >> temp;
  51.     if (temp == 1)
  52.         fill_keyb(a);
  53.     else
  54.         fill_rand(a);
  55.     if (symmetry(a))
  56.         cout << "Матрица симметрична относительно главной диагонали\n";
  57.     else
  58.         cout << "Матрица ассимметрична относительно главной диагонали\n";
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement