Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int n = 5;
  5.  
  6. void unos(int[][n]);
  7. void ispis(int[][n]);
  8. bool pogl(int[][n]);
  9. bool posp(int[][n]);
  10. bool posc(int[][n]);
  11.  
  12. int main()
  13. {
  14. int mat[n][n];
  15. unos(mat);
  16. ispis(mat);
  17. if (pogl(mat)) cout << "Simetricna po glavnoj dijagonali." << endl;
  18. else if (posp(mat)) cout << "Simetricna po sporednoj dijagonali." << endl;
  19. else if (posc(mat)) cout << "Simetricna po srednjem clanu." << endl;
  20.  
  21. return 0;
  22. }
  23. void unos(int mat[][n])
  24. {
  25. int m = n, i = 0, j = 0;
  26. for (int o = 1; o <= n / 2; o++)
  27. {
  28. for (j; j < m; j++) cin >> mat[i][j];
  29. j--;
  30. for (++i; i < m; i++) cin >> mat[i][j];
  31. i--;
  32. for (--j; j >= n - m; j--) cin >> mat[i][j];
  33. j++;
  34. for (--i; i >= o; i--) cin >> mat[i][j];
  35. m--;
  36. i = j = o;
  37. }
  38. if (n % 2 == 1)
  39. cin >> mat[n / 2][n / 2];
  40. }
  41.  
  42. void ispis(int mat[][n])
  43. {
  44. for (int i = 0; i < n; i++)
  45. {
  46. for (int j = 0; j < n; j++)
  47. cout << mat[i][j] << "\t";
  48. cout << endl;
  49. }
  50. }
  51.  
  52. bool pogl(int mat[][n])
  53. {
  54. for (int i = 0; i < n; i++)
  55. {
  56. for (int j = 0; j < n; j++)
  57. {
  58. if (mat[i][j] != mat[j][i])
  59. return false;
  60. }
  61. }
  62. return true;
  63. }
  64.  
  65. bool posp(int mat[][n])
  66. {
  67. for (int i = 0; i < n; i++)
  68. {
  69. for (int j = 0; j < n; j++)
  70. {
  71. if (mat[i][j] != mat[n - 1 - j][n - 1 - i])
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77.  
  78. bool posc(int mat[][n])
  79. {
  80. for (int i = 0; i < n; i++)
  81. {
  82. for (int j = 0; j < n; j++)
  83. {
  84. if (mat[i][j] != mat[n - 1 - i][n - 1 - j])
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement