这里是高斯-约旦消元法,和高斯消元法大同小异,重要的是思想
#include<bits/stdc++.h>
#define endl '\n'
#define int int64_t
using namespace std;
int n;
double a[105][105];
const int eps = 1e-10;
int Gauss() {
for (int i = 1; i <= n; ++i) {
int r = i;
for(int j = i;j <= n;++j)
if (fabs(a[j][i]) > eps) { r = j; break; }
if (r != i) swap(a[i], a[r]);
if (fabs(a[i][i]) <= eps) return 0;
for (int k = 1; k <= n; ++k) {
if (k == i) continue;
double t = a[k][i] / a[i][i];
for (int j = i; j <= n + 1; j++)
a[k][j] -= t * a[i][j];
}
}
for (int i = 1; i <= n; ++i)
a[i][n + 1] /= a[i][i];
return 1;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n + 1; ++j)
cin >> a[i][j];
if (!Gauss())cout << "No Solution" << endl,exit(0);
for (int i = 1; i <= n; ++i)
cout << fixed << setprecision(2) << a[i][n + 1] << endl;
return 0;
}