Advertisement
Vladislav_Bezruk

Untitled

Oct 5th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class matr {
  6. int **pf;
  7. int n, m;
  8.  
  9. public:
  10. void vvod() {
  11. cout<<"Enter n: ";
  12. cin>>n;
  13. cout<<"Enter m: ";
  14. cin>>m;
  15. pf = new int*[n];
  16. cout<<"Enter pf"<<"["<<n<<"] "<<"["<<m<<"]: " << endl;
  17. for(int i = 0; i < n; i++) {
  18. pf[i] = new int [m];
  19. for(int j = 0; j < m; j++) {
  20. cin>>pf[i][j];
  21. }
  22. }
  23. }
  24.  
  25. void vivod() {
  26. cout << "Matrix:" << endl;
  27. for(int i = 0; i < n; i++) {
  28. for(int j = 0; j < m; j++) {
  29. cout<<pf[i][j]<<" ";
  30. }
  31. cout<<endl;
  32. }
  33. cout<<endl;
  34. }
  35.  
  36. friend matr operator * (const matr &a, const matr &b);
  37. };
  38. matr operator*(const matr &a, const matr &b) {
  39. matr v;
  40. v.n = a.n;
  41. v.m = b.m;
  42.  
  43. v.pf = new int *[v.n];
  44.  
  45. for (int i = 0; i < v.n; i++)
  46. v.pf[i] = new int [v.m];
  47.  
  48. if(a.m == b.n) {
  49. for(int i = 0; i < v.n ; i++) {
  50. for(int j = 0; j < v.m; j++) {
  51. v.pf[i][j] = 0;
  52. for(int k = 0; k < a.m; k++) {
  53. v.pf[i][j] += (a.pf[i][k] * b.pf[k][j]);
  54. }
  55. }
  56. }
  57. }
  58. return v;
  59. }
  60. int main() {
  61. matr q, w;
  62. q.vvod();
  63. w.vvod();
  64. // q.vivod();
  65. // w.vivod();
  66. matr c;
  67. c = q * w;
  68. c.vivod();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement