Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include<iostream>
  2. #include <iomanip>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. void main(void)
  8. {// Определение переменных
  9. int
  10. a[3][3], b[3][3], c[3][3], d[3][3], i, j, m, n, m1, n1, f, l, max;
  11.  
  12. cout << "vvedite pa3Mep Matrici A:" << endl;
  13. cin >> n;
  14. cin >> m;
  15. cout << "vvedite pa3Mep Matrici B:" << endl;
  16. cin >> n1;
  17. cin >> m1;
  18. // проверка размерности матриц
  19. if (n1 >= m1)
  20. {
  21. max = n1;
  22. }
  23. else
  24. {
  25. max = m1;
  26. }
  27. if ((n == m) & (n == max))
  28. { // Заполнение матрицы А
  29. cout << "vvedite elementi Matrici A:" << endl;
  30. for (i = 1; i <= n; i++)
  31. {
  32. for (j = 1; j <= m; j++)
  33. cin >> a[i][j];
  34. }
  35. // Заполнение матрицы B
  36. cout << "vvedite elementi Matrici B:" << endl;
  37. for (i = 1; i <= n1; i++)
  38. {
  39. for (j = 1; j <= m1; j++)
  40. cin >> b[i][j];
  41. }
  42.  
  43. // Транспонирование матрицы В
  44. for (i = 1; i <= n1; i++)
  45. {
  46. for (j = 1; j <= m1; j++)
  47. {
  48. d[j][i] = b[i][j];
  49. }
  50. }
  51. // Умножение матриц В на В транспонированную
  52. for (i = 1; i <= n1; i++)
  53. {
  54. for (j = 1; j <= n1; j++)
  55. {
  56. f = 0;
  57. for (l = 1; l <= m1; l++)
  58. {
  59. f = f + b[i][l] * d[l][j];
  60. }
  61. c[i][j] = f;
  62. }
  63. }
  64. // Сложение матриц
  65. for (i = 1; i <= n1; i++)
  66. {
  67. for (j = 1; j <= n1; j++)
  68. {
  69. c[i][j] = a[i][j] + c[i][j];
  70. }
  71. }
  72. // Вывод матрицы A на экран
  73. printf("Matrica A: \n");
  74. for (i = 1; i <= n; i++)
  75. {
  76. for (j = 1; j <= m; j++)
  77. cout << setw(m) << a[i][j];
  78. cout << endl;
  79. }
  80. // Вывод матрицы B на экран
  81. printf("Matrica B: \n");
  82. for (i = 1; i <= n1; i++)
  83. {
  84. for (j = 1; j <= m1; j++)
  85. cout << setw(m) << b[i][j];
  86.  
  87. cout << endl;
  88. }
  89. // Вывод матрицы B транспонированной на экран
  90. printf("Matrica B(tpaHcnoHupoBaHHa9): \n");
  91. for (i = 1; i <= m1; i++)
  92. {
  93. for (j = 1; j <= n1; j++)
  94. cout << setw(n) << d[i][j];
  95. cout << endl;
  96. }
  97. // Вывод матрицы C на экран
  98. cout << "matrica C: \n";
  99. cout << endl;
  100. for (i = 1; i <= n1; i++)
  101. {
  102. for (j = 1; j <= n1; j++)
  103. cout << setw(n1) << c[i][j];
  104. cout << endl;
  105. }
  106. }
  107. else printf("Error!");
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement