Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class matr {
- int **pf;
- int n, m;
- public:
- void vvod() {
- cout<<"Enter n: ";
- cin>>n;
- cout<<"Enter m: ";
- cin>>m;
- pf = new int*[n];
- cout<<"Enter pf"<<"["<<n<<"] "<<"["<<m<<"]: " << endl;
- for(int i = 0; i < n; i++) {
- pf[i] = new int [m];
- for(int j = 0; j < m; j++) {
- cin>>pf[i][j];
- }
- }
- }
- void vivod() {
- cout << "Matrix:" << endl;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cout<<pf[i][j]<<" ";
- }
- cout<<endl;
- }
- cout<<endl;
- }
- friend matr operator * (const matr &a, const matr &b);
- };
- matr operator*(const matr &a, const matr &b) {
- matr v;
- v.n = a.n;
- v.m = b.m;
- v.pf = new int *[v.n];
- for (int i = 0; i < v.n; i++)
- v.pf[i] = new int [v.m];
- if(a.m == b.n) {
- for(int i = 0; i < v.n ; i++) {
- for(int j = 0; j < v.m; j++) {
- v.pf[i][j] = 0;
- for(int k = 0; k < a.m; k++) {
- v.pf[i][j] += (a.pf[i][k] * b.pf[k][j]);
- }
- }
- }
- }
- return v;
- }
- int main() {
- matr q, w;
- q.vvod();
- w.vvod();
- // q.vivod();
- // w.vivod();
- matr c;
- c = q * w;
- c.vivod();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement