Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cmath>
- #include <iostream>
- using namespace std;
- const int MAX = 15;
- long double A[MAX][MAX];
- long double B[MAX][MAX];
- const long double eps = 10E-14;
- long double calc(long double w)
- {
- if (fabs(w) < eps) return 0;
- else return w;
- }
- int main()
- {
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- scanf("%Lf", &A[j][i]);
- }
- }
- for (int i = 0; i < n; i++) B[i][i] = 1;
- for (int i = 0; i < n; i++)
- {
- printf("%8.4Lf", A[0][i]);
- for (int j = 1; j < n; j++) printf(" %8.4Lf", A[j][i]);
- printf("|%8.4Lf", B[0][i]);
- for (int j = 1; j < n; j++) printf(" %8.4Lf", B[j][i]);
- printf("\n");
- }
- printf("\n");
- for (int i = 0; i < n; i++)
- {
- if (A[i][i] != 1)
- {
- long double temp = 1 / A[i][i];
- for (int j = 0; j < n; j++)
- {
- A[j][i] = calc(A[j][i] * temp);
- B[j][i] = calc(B[j][i] * temp);
- }
- }
- for (int j = 0; j < n; j++)
- {
- if (j == i) continue;
- long double temp = A[i][j];
- for (int l = 0; l < n; l++)
- {
- A[l][j] = calc(A[l][j] - temp * A[l][i]);
- B[l][j] = calc(B[l][j] - temp * B[l][i]);
- }
- }
- for (int l = 0; l < n; l++)
- {
- printf("%8.4Lf", A[0][l]);
- for (int j = 1; j < n; j++) printf(" %8.4Lf", A[j][l]);
- printf("|%8.4Lf", B[0][l]);
- for (int j = 1; j < n; j++) printf(" %8.4Lf", B[j][l]);
- printf("\n");
- }
- printf("\n");
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement