#include #include #include #include using namespace std; void GetMinor(vector > A, vector > &B, int x, int y, int size) { int _x = 0; int _y; for (int i = 0; i < size; ++i) { if (i != x) { _y = 0; for (int j = 0; j < size; ++j) { if (j != y) { B[_x][_y] = A[i][j]; _y++; } } _x++; } } } //Finding determinant of matrix (size x size) double FindDeterminant(vector > A, int size) { if (size == 1) { return A[0][0]; } else { double det = 0; vector > Minor(size - 1, vector (size - 1)); for (int i = 0; i < size; ++i) { GetMinor(A, Minor, 0, i, size); det += pow(-1, i) * A[0][i] * FindDeterminant(Minor, size - 1); } return det; } } double InsertFreeCoeff(vector > A, vector B, int size, int j) { for (int i = 0; i < size; ++i) { A[i][j] = B[i]; } double det = FindDeterminant(A, size); return det; } void display() { setlocale(LC_ALL, "rus"); double *a = NULL, *b = NULL, **sum = NULL; const int N = 5; double x[N] = { -3, -1, 0, 1, 3 }, y[N] = { -4, -0.8, 1.6, 2.3, 1.5}; int K, i, j, k, m; double z, c; cout << "Порядок k= "; cin >> K; cin.get(); b = new double[K + 1]; a = new double[K + 1]; sum = new double *[K + 1]; for (int i = 0; i > A(K + 1, vector (K + 1)); vector B(K + 1); for (int i = 0; i < K + 1; i++) { for (int j = 0; j < K + 1; j++) { A[i][j] = sum[i][j]; } B[i] = b[i]; } //решаем методом Крамера double det = FindDeterminant(A, K + 1); if (det == 0) { cout << ">>>No roots!<<<" << endl; } else { cout << "det_A: " << det << endl; cout << "\n"; for (int i = 0; i < K + 1; ++i) { cout << "det_" << i << " = " << InsertFreeCoeff(A, B, K + 1, i) << "\n"; } cout << endl; cout << "Roots: " << endl; for (int i = 0; i < K + 1; ++i) { cout << "X" << i + 1 << " = " << InsertFreeCoeff(A, B, K + 1, i) / det << "\n"; } } system("Pause"); }