Advertisement
KedrikFeeD

Simetrical difficult

Dec 2nd, 2021
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     setlocale(LC_ALL, "Rus");
  5.     int dimension = 2;
  6.     int a[101][101];
  7.     cout << "Введите размерность матрицы (до 100):  ";
  8.     cin >> dimension;
  9.     cout << endl;
  10.     bool simetrical = true;
  11.     cout << "Как вы хотите проверить матрицу? Введите: \n";
  12.     cout << "1 - проверить симметричность матрицы по главной диагонали,\n";
  13.     cout << "2 - проверить симметричность матрицы по побочной диагонали,\n";
  14.     cout << "0 - чтобы завершить проверку\n";
  15.     short choice = 3;
  16.     while (choice != 0) {
  17.         cin >> choice;
  18.         if (choice = 1) {
  19.             cout << "Введите матрицу:\n";
  20.             for (int i = 0; i < dimension; i++) {
  21.                 for (int j = 0; j < dimension; j++) {
  22.                     cin >> a[i][j];
  23.                 }
  24.                 cout << endl;
  25.             }
  26.             cout << endl;
  27.             for (int i = 0; i < dimension; i++) {
  28.                 for (int j = 0; j < dimension; j++) {
  29.                     cout << a[i][j];
  30.                     cout << "\t";
  31.                 }
  32.                 cout << endl;
  33.             }
  34.             for (int i = 0; i < dimension; i++) {
  35.                 for (int j = 0; j < dimension; j++) {
  36.                     if (i < j) {
  37.                         if (a[i][j] != a[j][i]) {
  38.                             simetrical = false;
  39.                         }
  40.  
  41.                     }
  42.                 }
  43.             }
  44.             if (simetrical) {
  45.                 cout << "Матрица симметрична!";
  46.             }
  47.             else {
  48.                 cout << "Матрица не симметрична!";
  49.             }
  50.             simetrical = true;
  51.         }
  52.         else if (choice = 2) {
  53.             cout << "Введите матрицу:\n";
  54.             for (int i = 0; i < dimension; i++) {
  55.                 for (int j = 0; j < dimension; j++) {
  56.                     cin >> a[i][j];
  57.                 }
  58.                 cout << endl;
  59.             }
  60.             cout << endl;
  61.             for (int i = 0; i < dimension; i++) {
  62.                 for (int j = 0; j < dimension; j++) {
  63.                     cout << a[i][j];
  64.                     cout << "\t";
  65.                 }
  66.                 cout << endl;
  67.             }
  68.             for (int i = 0; i < dimension; i++) {
  69.                 for (int j = 0; j < dimension; j++) {
  70.                     if (i + j < dimension + 1) {
  71.                         if (a[i][j] != a[j][i]) {
  72.                             simetrical = false;
  73.                         }
  74.  
  75.                     }
  76.                 }
  77.             }
  78.  
  79.             if (simetrical) {
  80.                 cout << "Матрица симметрична!\n";
  81.             }
  82.             else {
  83.                 cout << "Матрица не симметрична!\n";
  84.             }
  85.             simetrical = true;
  86.         }
  87.         cout << "Как вы хотите проверить матрицу? Введите: \n";
  88.         cout << "1 - проверить симметричность матрицы по главной диагонали,\n";
  89.         cout << "2 - проверить симметричность матрицы по побочной диагонали,\n";
  90.         cout << "0 - чтобы завершить проверку\n";
  91.        
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement