Off[General::spell1];
Clear[Pivot,a0,p,s];
Pivot[a0_] :=
Module[{a,i,j,k,n, x,
    smax, rmax, xmult, sum}, 
  a = a0;
  n = Length[a];
  x=Table[a[[i,j]],{i,1,n},{j,1,n}];
Clear[i,j];
For[i=1, i <= n, i++,
   p[i]=i; smax =0;
  For[j=1, j <= n, j++,
   smax = Max[ smax, Abs[a[[i,j]]] ];  
  ];
  s[i] = smax;
];    
For[k=1,k<=n-1,k++,
   rmax =Abs[x[[p[k],k]]]/s[p[k]]; 
   Block[{i,j,l}, 
    For[j=k+1,j<=n,j++,
     r = N[ Abs[ x[[ p[j],k ]]/
        s[ p[j] ] ] , digit];
     If[r > rmax,   
      t=p[k]; p[k]=p[j]; p[j]=t ];           
    ]; 
    For[i=k+1, i <=n, i++,
        xmult= N[x[[p[i],k]]/
             x[[p[k],k]], digit];
      x[[ p[i],k]] = xmult;
      For[l=k+1, l <=n, l++,  
       x[[ p[i],l]]= N[x[[ p[i],l]]-
         xmult * x[[ p[k],l]], digit];
      ];
    ];
 ];]; 
 Clear[P];
 P = Table[p[i], {i,1,n}];
Return[x]; ]; 
 On[General::spell1];

Off[General::spell1];
Clear[GaussPivot,a0,b0];
GaussPivot[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] 
   ];
];   
x[[n]] = N[b[[ p[n] ]]/a[[ p[n],n]],
 							 digit]; Clear[i,j,k];
For[i=n-1,1<=i,i--,
    sum = b[[ p[i] ]];
    For[j=i+1,j<=n,j++,
      sum  = N[sum - 
          a[[ p[i],j]]*x[[j]],digit] 
    ]; 
    x[[i]] = N[sum/a[[p[i],i]],digit];   
];
Return[x]; ];  
On[General::spell1];

Clear[digit];
digit = 10;

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};
MatrixForm[A]

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

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]

Clear[A,B]; 
A = {{2,3,-4,1},{1,-1,0,-2},{3,3,4,3},{4,1,0,4}};
B = {9,3,-8,0};
MatrixForm[A]

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