From 506b43bc31c0b1d3b87013508c19913484dc0c47 Mon Sep 17 00:00:00 2001 From: Nehal Chaudhari <58935474+nehalchaudhari31@users.noreply.github.com> Date: Fri, 29 Oct 2021 10:56:12 +0530 Subject: [PATCH] Symmetric or Skew symmetric matrix in C++ Hacktoberfest 2021 --- Symmetric or Skew symmetric matrix in C++ | 98 +++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Symmetric or Skew symmetric matrix in C++ diff --git a/Symmetric or Skew symmetric matrix in C++ b/Symmetric or Skew symmetric matrix in C++ new file mode 100644 index 00000000..c7e2c0eb --- /dev/null +++ b/Symmetric or Skew symmetric matrix in C++ @@ -0,0 +1,98 @@ +nor skew symmetric. +Code + +#include +using namespace std; + +int main() + +{ + int n; + + cout << "Enter size of square matrix\n"; //inputting size of the matrix + + cin >> n; + + int a[n][n]; + + cout << "Enter the matrix row-wise\n"; //inputting the matrix row wise + + for (int i = 0; i < n; ++i) + + { + for (int j = 0; j < n; ++j) + + { + + cin >> a[i][j]; + } + } + + int ctr = 1; + + for (int i = 0; i < n; ++i) //check for symmetric matrix + + { + for (int j = 0; j < n; ++j) + + { + + if (a[i][j] != -a[j][i]) + + { + + ctr = 0; + + break; + } + } + + if (ctr == 0) + + break; + } + + if (ctr) //printing if matrix is symmetric + + cout << "Matrix is skew-symmetric\n"; + + else //checking if skew symmetric matrix + + { + ctr = 1; + + for (int i = 0; i < n; ++i) + + { + + for (int j = 0; j < n; ++j) + + { + + if (a[i][j] != (-a[j][i])) + + { + + ctr = 0; + + break; + } + } + + if (ctr == 0) + + break; + } + + if (ctr) //printing if matrix is skew symmetric matrix + + cout << "Matrix is skew-symmetric\n"; + + else //if not then its neither of the two + + cout << "Matrix is neither symmetric nor skew-symmetric\n"; + } + + return 0; + +}