Off[General::spell1];
Clear[GaussLU,a0,p,s];
GaussLU[a0_] := 
Module[{a,i,j,k,n,x,z},
  a = a0;
  n = Length[a];
    x=Table[a[[i,j]],{i,1,n},{j,1,n}];
    For[i=1,i<=n,i++, p[i]=i];
    For[i=1,i<=n,i++, 
       s[i]=Max[Table[Abs[a[[i,j]]],						{j,1,n}]] ];
     For[k=1,k<=n-1,k++,
      Block[{l,i,j},
      For[j=k+1,j<=n,j++,
         If[Abs[x[[p[j],k]]]/s[p[j]]
           > Abs[x[[p[k],k]]]/s[p[k]],
       t=p[k]; p[k]=p[j]; p[j]=t ]; ];
      For[i=k+1,i<=n,i++,
         z = N[x[[p[i],k]]/x[[p[k],
           k]],digit];
          x[[p[i],k]]=z; 
          For[l=k+1,l<=n,l++,
           x[[p[i],l]]=N[x[[p[i],l]]-
             z x[[p[k],l]],digit];
      ];];];];
    Clear[P,Q,L,U,T];     
    P=Table[p[i],{i,1,n}];
    Q=Table[0,{i,1,n},{j,1,n}]; 
    For[i=1,i<=n,i++, Q[[i,p[i]]]=1];
    T=Q.x; 
    L=Table[If[i !=j,  If[i > j,
       T[[i,j]], 0],1],{i,n},{j,n}];  
    U=Table[If[i <=j, T[[i,j]], 0],    						{i,n},{j,n}];     
    Return[x]; ];
On[General::spell1];

Clear[digit];
digit = 10;

Clear[A];
A = {{2,3,-6},{1,-6,8},{3,-2,1}}; 
TableForm[A]

Clear[LU];
LU = GaussLU[A];
MatrixForm[LU]

P

TableForm[L]//N 
TableForm[U]//N

TableForm[L.U - Q.A]

Clear[A];
A = {{2,4,-4,0},{1,5,-5,-3},{2,3,1,3},{1,4,-2,2}};

Clear[LU];
LU = GaussLU[A];
MatrixForm[LU]//N

P

TableForm[L]//N 
TableForm[U]//N

Off[General::spell1];
Clear[GaussSol,a0,b0];
GaussSol[a0_,b0_] :=
Module[{a,b,k,n,x}, 
  a = a0;
  b = b0;  
  n = Length[b];
  x = Table[0,{i, n}];
  Clear[i,k];
  For[k=1,k<=n-1,k++,
    For[i=k+1,i<=n,i++,
    b[[p[i]]] =N[ b[[p[i]]] -
      a[[p[i],k]] b[[p[k]]],digit] ];];
  Clear[i,j];
  For[i=n,1<=i,i--,
     x[[i]] = N[(b[[p[i]]] - 
      Sum[a[[p[i],j]] x[[j]], 
      {j, i+1, n}])/a[[p[i],i]],digit]; ];
  Return[x]; ];  
 On[General::spell1];

Clear[A,B]; 
A = {{2,4,-4,0},{1,5,-5,-3},{2,3,1,3},{1,4,-2,2}};
B = {12,18,8,8};
StringForm["A= ``    B = ``", MatrixForm[A], MatrixForm[B]]

Clear[LU];
LU=GaussLU[A];
GaussSol[LU,B]//N

Clear[A,B]; 
A = {{1,2,-4},{2,4,-5},{2,3,1}};
B = {12,18,8 };
MatrixForm[A]

Pivot[A];
N[ GaussPivot[Pivot[A],B], 7]