Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions Symmetric or Skew symmetric matrix in C++
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
nor skew symmetric.
Code

#include <iostream>
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;

}