Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- int main() {
- int m, n, original[64][64], copy[64][64], result[64][64] = { 0 };
- cin >> n >> m;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- cin >> original[row][col];
- copy[row][col] = original[row][col];
- }
- }
- for (int i = 0; i < m - 1; i++)
- {
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- int sum = 0;
- for (int k = 0; k < n; k++)
- {
- sum += original[row][k] * copy[k][col];
- }
- result[row][col] = sum;
- }
- }
- for (int j = 0; j < n; j++)
- {
- for (int k = 0; k < n; k++)
- {
- original[j][k] = result[j][k];
- }
- }
- }
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- cout << original[row][col] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement