Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. using namespace std;
  2.  
  3. #include <iostream>
  4.  
  5. int main() {
  6.     int m, n, original[64][64], copy[64][64], result[64][64] = { 0 };
  7.     cin >> n >> m;
  8.     for (int row = 0; row < n; row++)
  9.     {
  10.         for (int col = 0; col < n; col++)
  11.         {
  12.             cin >> original[row][col];
  13.             copy[row][col] = original[row][col];
  14.         }
  15.     }
  16.     for (int i = 0; i < m - 1; i++)
  17.     {
  18.         for (int row = 0; row < n; row++)
  19.         {
  20.             for (int col = 0; col < n; col++)
  21.             {
  22.                 int sum = 0;
  23.                 for (int k = 0; k < n; k++)
  24.                 {
  25.                     sum += original[row][k] * copy[k][col];
  26.                 }
  27.                 result[row][col] = sum;
  28.             }
  29.         }
  30.         for (int j = 0; j < n; j++)
  31.         {
  32.             for (int k = 0; k < n; k++)
  33.             {
  34.                 original[j][k] = result[j][k];
  35.             }
  36.         }
  37.     }
  38.    
  39.  
  40.     for (int row = 0; row < n; row++)
  41.     {
  42.         for (int col = 0; col < n; col++)
  43.         {
  44.             cout << original[row][col] << " ";
  45.         }
  46.         cout << endl;
  47.     }
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement