define _CRT_SECURE_NO_WARNI NGS include iostream include iomanip inclu

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#define vd vector<double>
#define vvd vector<vector<double> >
#define ui unsigned int
using namespace std;
vvd a;
vvd b;
vd temp;
int n;
double eps = 1e-6;
vd operator /( vd a, double num)
{
vd rez;
rez.resize(a.size());
for (int i = 0; i < a.size(); ++i) {
rez[i] = a[i] /num;
}
return rez;
}
vd operator -( vd a, vd b)
{
vd rez;
rez.resize(a.size());
for (int i = 0; i < a.size(); ++i) {
rez[i] = a[i] - b[i];
}
return rez;
}
vd operator *( vd a, double num)
{
vd rez;
rez.resize(a.size());
for (int i = 0; i < a.size(); ++i) {
rez[i] = a[i] * num;
}
return rez;
}
int main ()
{
freopen("input.txt", "r", stdin);
cin >> n;
a.resize(n, vd(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n ; ++j) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n ; ++j) {
cout << a[i][j] <<" ";
}
cout << endl;
}
for (int N = 0; N < n; ++N) {
for (int j = N; j < n; ++j) {
for (int i = N; i < n ; ++i) {
if (fabs(a[i][j]) > eps)
{
if (fabs(a[N][j]) < eps)
{
temp = a[N];
a[N] = a[i];
a[i] = temp;
}
a[N] = a[N]/a[N][N];
for (int k = N + 1; k < n; ++k)
{
a[k] = a[k] - a[N]*a[k][N];
}
/*for (int i = 0; i < n; ++i) {
for (int j = 0; j < n ; ++j) {
cout << a[i][j] <<" ";
}
cout << endl;
}*/
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n ; ++j) {
cout << a[i][j] <<" ";
}
cout << endl;
}
for (int M = n - 1; M > 0; --M)
{
for (int s = M - 1; s > 0; --s)
{
a[s] = a[s] - a[M] * a[s][M];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n ; ++j) {
cout << a[i][j] <<" ";
}
cout << endl;
}
}