csansoon

P8.08 P88905 Products of matrices

Nov 29th, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4.  typedef vector< vector <int> > Matrix;
  5.  
  6. Matrix product (const Matrix& a, const Matrix& b) {
  7.   Matrix c (a.size(), vector<int> (b[0].size()));
  8.   int sum = 0;
  9.   for (int i = 0; i < a.size(); ++i) {
  10.     for (int j = 0; j < b[0].size(); ++j) {
  11.       for(int k = 0; k < b.size(); ++k) {
  12.         sum = c[i][j] + a[i][k] * b[k][j];
  13.         c[i][j] = sum;
  14.       }
  15.     }
  16.   }
  17.   return c;
  18. }
  19.  
  20. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment