Pagini recente » Cod sursa (job #1835448) | Cod sursa (job #155870) | Cod sursa (job #1664825) | Cod sursa (job #1062869) | Cod sursa (job #1689751)
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int nmax = 309;
int p[nmax] , i , j , k , n , m , first;
double a[nmax][nmax] , x[nmax] , c;
int main()
{
ifstream fin("gauss.in");
ofstream fout("gauss.out");
fin >> n >> m;
for (i = 1 ; i <= n ; ++i)
for (j = 1 ; j <= m + 1 ; ++j)
fin >> a[i][j];
for (i = 1 ; i <= n ; ++i)
{
first = 1;
while (-eps < a[i][first] && a[i][first] < eps) first++;
if (first == m + 2) continue;
if (first == m + 1)
{
printf("Imposibil\n");
return 0;
}
for (j = 1 ; j <= n ; ++j)
{
if (i == j) continue;
c = a[j][first] / a[i][first];
for (k = 1 ; k <= m + 1 ; ++k)
a[j][k] -= a[i][k] * c;
}
p[i] = first;
}
for (i = 1 ; i <= m ; ++i)
if (p[i]) x[p[i]] = a[i][m + 1] / a[i][p[i]];
for (i = 1 ; i <= m ; ++i)
fout << fixed << setprecision(10) << x[i] << '\n';
return 0;
}