csansoon

P8.03 P37390 Product of square matrices

Nov 28th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 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.     int size=a.size();
  8.     Matrix c(size,vector <int> (size));
  9.     for (int i=0; i<size; ++i) for (int j=0; j<size; ++j) {
  10.         int n=0;
  11.         for (int k=0; k<size; ++k) n = n + (a[i][k] * b[k][j]);
  12.         c[i][j] = n;
  13.     }
  14.     return c;
  15. }
  16.  
  17. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment