Advertisement
Sanlover

Untitled

Jun 24th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int N; // Размер матрицы
  7. cout << "Enter the size of matrix: ";
  8. cin >> N;
  9.  
  10. // Создали первую матрицу
  11. int** firstMatrix = new int* [N];
  12. for (int i = 0; i < N; i++)
  13. firstMatrix[i] = new int[N];
  14.  
  15. // Вторую матрицу
  16. int** secondMatrix = new int* [N];
  17. for (int i = 0; i < N; i++)
  18. secondMatrix[i] = new int[N];
  19.  
  20. // И матрицу - результат
  21. int** result = new int* [N];
  22. for (int i = 0; i < N; i++)
  23. result[i] = new int[N];
  24.  
  25. // Заполняем первую
  26. cout << "Fill the first matrix:" << endl;
  27. for (int i = 0; i < N; i++)
  28. for (int j = 0; j < N; j++)
  29. {
  30. cout << "[" << i << "]" << "[" << j << "] = ";
  31. cin >> firstMatrix[i][j];
  32. cout << endl;
  33. }
  34. // Отступаем
  35. cout << endl;
  36.  
  37. // Заполняем вторую
  38. cout << "Fill the second matrix:" << endl;
  39. for (int i = 0; i < N; i++)
  40. for (int j = 0; j < N; j++)
  41. {
  42. cout << "[" << i << "]" << "[" << j << "] = ";
  43. cin >> secondMatrix[i][j];
  44. cout << endl;
  45. }
  46.  
  47. cout << endl << "Results:" << endl;
  48.  
  49.  
  50. // ПОдсчёт
  51. for(int i = 0 ; i < N; i++ )
  52. {
  53. for(int j = 0 ; j < N ; j++)
  54. {
  55. int temp = 0;
  56. for (int k = 0; k < N; k++)
  57. temp += firstMatrix[i][k] * secondMatrix[k][j];
  58.  
  59.  
  60. result[i][j] = temp;
  61. }
  62. }
  63.  
  64.  
  65. for(int i = 0; i < N; i++)
  66. {
  67. for (int j = 0; j < N; j++)
  68. cout << result[i][j] << " ";
  69. cout << endl;
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement