daily pastebin goal
22%
SHARE
TWEET

Tích ma trận với ma trận chuyển vị

llvlleo1810 Apr 17th, 2018 (edited) 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (INPUT
  2. 2 2
  3. 1 2
  4. 3 4
  5. OUTPUT
  6. 5 11
  7. 11 25)
  8. #include<iostream>
  9. using namespace std;
  10. int a[100][100];
  11. int b[100][100];
  12. int c[100][100];
  13. int n,m;
  14.  
  15. void input() {
  16.  cin >> n >> m;
  17.  for(int i = 0; i < n; i++)
  18.   for(int j = 0; j < m; j++)
  19.    cin >> a[i][j];
  20. }
  21.  
  22. void cvi() {
  23.  for(int i = 0; i < n; i++) {
  24.   for(int j = 0; j < m; j++) {
  25.    b[j][i] = a[i][j];
  26.   }
  27.  }
  28. }
  29. void tich() {
  30.  for(int i = 0; i < n; i++) {
  31.   for(int j = 0; j < n; j++) {
  32.    for(int l = 0; l < m; l++) {
  33.     c[i][j] += a[i][l] * b[l][j];
  34.    }
  35.   }
  36.  }
  37.  for(int i = 0; i < n; i++) {
  38.   for(int j = 0; j < n; j++) {
  39.    cout << c[i][j] << " ";
  40.   }
  41.   cout << endl;
  42.  }
  43. }
  44.  
  45. int main() {
  46.  input();
  47.  cvi();
  48.  tich();
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top