Pagini recente » Cod sursa (job #2637750) | Cod sursa (job #818444) | Cod sursa (job #2566612) | Cod sursa (job #1076659) | Cod sursa (job #1752438)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 309;
const double eps = 0.00000001;
double a[nmax][nmax];
int p[nmax];
double ret[nmax] , x;
int i , j , n , m , k;
inline bool zero(double x)
{
if (-eps < x && x < eps) return true;
return false;
}
int main()
{
ifstream fin("gauss.in");
ofstream fout("gauss.out");
fin >> m >> n;
for (i = 1 ; i <= m ; ++i)
for (j = 1 ; j <= n + 1 ; ++j)
fin >> a[i][j];
for (i = 1 ; i <= m ; ++i)
{
for (j = 1 ; j <= n + 1 && zero(a[i][j]) ; ++j);
if (j == n + 2) continue;
if (j == n + 1)
{
fout << "Imposibil\n";
return 0;
}
p[i] = j;
x = a[i][p[i]];
for (j = 1 ; j <= n + 1 ; ++j)
a[i][j] /= x;
for (j = 1 ; j <= m ; ++j)
{
if (i == j) continue;
x = a[j][p[i]];
if (zero(x)) continue;
for (k = 1 ; k <= n + 1 ; ++k)
a[j][k] = a[j][k] / x - a[i][k];
}
}
for (i = 1 ; i <= m ; ++i)
if (p[i]) ret[p[i]] = a[i][n + 1] / a[i][p[i]];
for (i = 1 ; i <= n ; ++i)
fout << fixed << setprecision(10) << ret[i] << " ";
fout << '\n';
return 0;
}