#include <iostream>
using namespace std;
int main()
{
int n=0;
cout << "Podaj n: ";
cin >> n;
double sum=0;
double a[n][n];
double b[n];
double c[n][n+1];
double x[n];
for(int i=1; i<=n ; i++)
{
for(int j=1; j<=n; j++)
{
cout <<"Podaj a[" <<i<< "][" <<j<<"]:";
cin >> a[i-1][j-1];
}
cout << endl;
}
for(int i=1; i<=n; i++)
{
cout << "Podaj b[" << i << "]:";
cin >> b[i-1];
}
for(int i=1; i<=n ; i++)
{
for(int j=1; j<=n; j++)
{
c[i-1][j-1] = a[i-1][j-1];
}
}
for(int i=1; i<=n; i++)
{
c[i-1][n] = b[i-1];
}
for (int s=1; s<=(n-1) ;s++ )
{
for (int i=s+1; i<=n ;i++ )
{
for (int j=s+1; j<=(n+1) ;j++ )
{
c[i-1][j-1] = (c[i-1][j-1]-(c[i-1][s-1] /
/ c[s-1][s-1]) * c[s-1][j-1]);
}
}
}
x[n-1] = (c[n-1][n] / c[n-1][n-1]);
for(int i=n-1; i>=1; i--)
{
sum=0;
for(int s=i+1;s<=n;s++)
{
sum=sum+(c[i-1][s-1]*x[s-1]);
}
x[i-1]= (c[i-1][n]-sum)/c[i-1][i-1];
}
for(int i=1; i<=n; i++)
{
cout << "x[" <<i << "] = " << x[i-1] << endl;
}
system("PAUSE");
return 0;
}