Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- 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()
- {
- ifstream input;
- ofstream report;
- input.open("input.txt");
- if (!input.is_open()) cout << "Ошибка при открытии файла!\t\n";
- report.open("output.txt");
- 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;
- n = 4; cout << "3\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++) { input >> a[i][j]; cout << a[i][j] << " "; } cout << endl; } cout << endl;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++) b[i][j] = a[i][j]; //Создание матрицы B
- cout << "Введите степень: ";
- //cin >> st;
- cout << "3\n"; st = 3;
- 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++)
- {
- int ss = a[i][k] * b[k][j];
- report << "ss= " << a[i][k] << " * " << b[k][j] << endl;
- s += ss;
- report << "i=" << i + 1 << " j=" << j + 1 << " k=" << k + 1 << " сумма в строке=" << ss + 1 << endl; //report
- }
- c[i][j] = s;
- report << endl; //report
- }
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++) a[i][j] = c[i][j];
- report << "\t\t\t\t\t\t\t\tST=" << st << endl;
- }
- }
- for (i=0; i<n; i++)
- {
- for (j = 0; j < n; j++) cout << a[i][j] << " ";
- cout << endl;
- }
- report.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment