Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void identity(int N)
- {
- int i, j;
- int a[10][10];
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < N; j++)
- {
- if (i == j) a[i][j] = 1;
- else a[i][j] = 0;
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- void main()
- {
- setlocale(LC_ALL, "");
- const int nn = 10;
- int a[nn][nn], b[nn][nn], c[nn][nn];
- int n, p, k, i, j, st;
- cout << "Введите ранг матрицы: ";
- cin >> n;
- cout << "Введите матрицу:\n";
- for (i = 0; i < n; i++)
- for ( j = 0; j < n; j++)
- cin >> a[i][j]; //Ввод матрицы A
- cout << endl;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++) b[i][j] = a[i][j]; //Создание матрицы B
- cout << "Введите степень: ";
- cin >> st;
- switch (st)
- {
- case 0:
- identity(n);
- break;
- case 1:
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++) cout << a[i][j] << " ";
- cout << endl;
- }
- break;
- default:
- while (--st != 0)
- {
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- {
- int s = 0;
- for (int k = 0; k < n; k++)
- s += a[i][k] * b[k][j];
- c[i][j] = s;
- }
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++) a[i][j] = c[i][j];
- }
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++) cout << a[i][j] << " ";
- cout << endl;
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment