import java.io.*;

class SCO10C1
{
  public static double[] gaussjordan(double a[][],double b[])
  { //pivotsuz
  int n=b.length;
  int np1=n+1;
  double C[][]=new double[n][np1];
  double x[]=new double[n];
  double carpan=0;
  int i,j,k,ii=0,jj,p;
  double buyuk,dummy;
  
  for(i=0;i<n;i++)
  {for(j=0;j<n;j++){C[i][j]=a[i][j];};C[i][n]=b[i];}

  for(k=0;k<n;k++)
  { //pivotlama
	p=k;
	buyuk=Math.abs(a[k][k]);
	for(ii=k+1;ii<n;ii++)
	{  dummy=Math.abs(a[ii][k]);
	   if(dummy > buyuk) {buyuk=dummy;p=ii;}
	}
	if(p!=k)
	{ for(jj=k;jj<np1;jj++)
	  { dummy=C[p][jj];
	    C[p][jj]=C[k][jj];
	    C[k][jj]=dummy;
	  }
	}
	//gauss jordan eleme
	for(j=k+1;j<np1;j++)
	{ C[k][j]/=C[k][k]; }
	for(i=0;i<n;i++)
    {  if(i!=k)
       {  carpan=C[i][k];
          C[i][k]=0;
          for(j=k+1;j<np1;j++)
          {   C[i][j]-=carpan*C[k][j]; }
       }    
	}
  }
  for(i=0;i<n;i++)
  {x[i]=C[i][n];}
  return x;
  } 	
      
  public static void main(String args[]) throws IOException
  {
  //double a[][]={{3,-0.1,-0.2},{0.1,7,-0.3},{0.3,-0.2,10}};
  //double b[]={7.85,-19.3,71.4};
  double a[][]={{2800,-2800,0,0,0},{-2800,5600,-2800,0,0},{0,-2800,5600,-2800,0},{0,0,-2800,5600,-2800},{0,0,0,-2800,2800}};
  double b[]={1125,2250,2250,2250,1125};
  double x[]=gaussjordan(a,b);
  Text.print(x,"pivotlu Gauss Jordan Metodu çözümü");
  }
}