Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. const int MAX = 15;
  7. long double A[MAX][MAX];
  8. long double B[MAX][MAX];
  9. const long double eps = 10E-14;
  10.  
  11. long double calc(long double w)
  12. {
  13. if (fabs(w) < eps) return 0;
  14. else return w;
  15. }
  16.  
  17. int main()
  18. {
  19. int n;
  20. scanf("%d", &n);
  21. for (int i = 0; i < n; i++)
  22. {
  23. for (int j = 0; j < n; j++)
  24. {
  25. scanf("%Lf", &A[j][i]);
  26. }
  27. }
  28. for (int i = 0; i < n; i++) B[i][i] = 1;
  29. for (int i = 0; i < n; i++)
  30. {
  31. printf("%8.4Lf", A[0][i]);
  32. for (int j = 1; j < n; j++) printf(" %8.4Lf", A[j][i]);
  33. printf("|%8.4Lf", B[0][i]);
  34. for (int j = 1; j < n; j++) printf(" %8.4Lf", B[j][i]);
  35. printf("\n");
  36. }
  37. printf("\n");
  38. for (int i = 0; i < n; i++)
  39. {
  40. if (A[i][i] != 1)
  41. {
  42. long double temp = 1 / A[i][i];
  43. for (int j = 0; j < n; j++)
  44. {
  45. A[j][i] = calc(A[j][i] * temp);
  46. B[j][i] = calc(B[j][i] * temp);
  47.  
  48. }
  49. }
  50. for (int j = 0; j < n; j++)
  51. {
  52. if (j == i) continue;
  53.  
  54. long double temp = A[i][j];
  55. for (int l = 0; l < n; l++)
  56. {
  57. A[l][j] = calc(A[l][j] - temp * A[l][i]);
  58. B[l][j] = calc(B[l][j] - temp * B[l][i]);
  59.  
  60. }
  61. }
  62.  
  63. for (int l = 0; l < n; l++)
  64. {
  65. printf("%8.4Lf", A[0][l]);
  66. for (int j = 1; j < n; j++) printf(" %8.4Lf", A[j][l]);
  67. printf("|%8.4Lf", B[0][l]);
  68. for (int j = 1; j < n; j++) printf(" %8.4Lf", B[j][l]);
  69. printf("\n");
  70. }
  71. printf("\n");
  72.  
  73. }
  74. system("pause");
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement