Write a program to find the transpose of a given matrix and check whether it is symmetric or not
Example:
Input: matrix={{1,7,3},{7,4,-5},{3,-5,6}}
Output: Symmetric
Approach
C++
#include <bits/stdc++.h>using namespace std;bool isSymmetric(vector<vector<int>> matrix){//squae matrixint n = matrix.size();int transpose[n][n];for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){transpose[j][i] = matrix[i][j];}}for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){if (transpose[i][j] != matrix[i][j]){return false;}}}return true;}int main(){//square matrixvector<vector<int>> matrix = {{1, 7, 3},{7, 4, -5},{3, -5, 6}};if (isSymmetric(matrix))cout << "Symmetric\n";elsecout << "Not Symmetric\n";return 0;}
No comments:
Post a Comment