fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a1, b1;
  6. cout << "Enter the number of rows and columns of the matrix: ";
  7. cin >> a1 >> b1;
  8.  
  9.  
  10. if (a1 != b1) {
  11. cout << "The matrix is not square, It is not symmetric." << endl;
  12. return 0;
  13. }
  14.  
  15. int matrix[a1][b1];
  16.  
  17.  
  18. cout << "Enter the elements:" << endl;
  19. for (int i = 0; i < a1; i++) {
  20. for (int j = 0; j < b1; j++) {
  21. cin >> matrix[i][j];
  22. }
  23. }
  24.  
  25. int flag = 0;
  26.  
  27.  
  28. for (int i = 0; i < a1; i++) {
  29. for (int j = 0; j < b1; j++) {
  30. if (matrix[i][j] != matrix[j][i]) {
  31. flag = 1;
  32. break;
  33. }
  34. }
  35. if (flag == 1) {
  36. break;
  37. }
  38. }
  39.  
  40. if (flag == 0) {
  41. cout << "The matrix is symmetric." << endl;
  42. } else {
  43. cout << "The matrix is not symmetric." << endl;
  44. }
  45.  
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter the number of rows and columns of the matrix: The matrix is not square, It is not symmetric.