Created
August 5, 2014 19:58
-
-
Save Zulqurnain/1679508b9891efde70ce to your computer and use it in GitHub Desktop.
C++ program to find that given N*M matrix is symmatric or anti symmetric.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include<iostream> | |
| #include <Windows.h> | |
| using namespace std; | |
| int main(){ | |
| int rows, col, i, j; | |
| cout << "Enter Number of Rows of Matrix :=:"; cin >> rows; cout << "\n"; | |
| cout << "Enter Number of coloumns of Matrix :=:"; cin >> col; cout << "\n"; | |
| /* initializing my matrix */ | |
| double **matrix; | |
| matrix = new double *[rows]; | |
| for (int t = 0; t < rows; t++){ | |
| matrix[t] = new double[col]; | |
| } | |
| /* Giving Input in matrix */ | |
| for (i = 0; i< rows; i++){ | |
| for (j = 0; j < col; j++){ | |
| cout << "Enter Value in Matrix Location [" << i << "][" << j << "] :=:"; cin >> matrix[i][j]; cout << "\n"; | |
| } | |
| } | |
| /* Checking Matrix Is Sysmmetric or anti symmetric */ | |
| /* if symmetric A = A(transpose) and if anti symmetric A = -A(transpose)*/ | |
| bool symmetric = true, antisymmetric = true; | |
| for (i = 0; i< rows; i++){ // symmetric | |
| for (j = 0; j < col; j++){ | |
| if (matrix[i][j] != matrix[j][i]){ | |
| symmetric = false; | |
| } | |
| } | |
| } | |
| if (symmetric == false){ // non symmetric checking | |
| for (i = 0; i< rows; i++){ // symmetric | |
| for (j = 0; j < col; j++){ | |
| if (matrix[i][j] != (matrix[j][i] * -1)){ | |
| antisymmetric = false; | |
| } | |
| } | |
| } | |
| if (antisymmetric == true){ | |
| cout << "::Matrix is Anti Symmetric::\n"; | |
| } | |
| } | |
| else{ | |
| cout << "::Matrix is Symmetric::\n"; | |
| } | |
| /*Deleting Allocated memory*/ | |
| for (int p = 0; p < rows; p++){ | |
| delete [] matrix[p]; | |
| } | |
| delete matrix; | |
| system("PAUSE"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment