(*Input data*)
Gauss[AInput_,bInput_]:=(
A=AInput;
b=bInput;
n=Length[A];
(*Forward elimination*)
For[i=1, i≤n, i++,
(*Find the index of the row with maximal element*)
maxIndex=i;
For[j=i+1,j≤n,j++,
If[Abs[A[[j,i]]]>Abs[A[[maxIndex,i]]],
maxIndex=j]
];
(*Change the rows with indices i and maxIndex*)
For[j=i, j≤n, j++,
temp=A[[i,j]];
A[[i,j]]=A[[maxIndex,j]];
A[[maxIndex,j]]=temp;
];
temp=b[[i]];
b[[i]]=b[[maxIndex]];
b[[maxIndex]]=temp;
(*Eliminate the elements under the main diagonal in the i-th column*)
For[j=i+1,j≤n,j++,
l=((A[[j,i]])/(A[[i,i]]));
A[[j,i]]=0;
For[k=i+1,k≤n,k++,
A[[j,k]]=A[[j,k]]-l*A[[i,k]];
];
b[[j]]=b[[j]]-l*b[[i]];
]
];
(*Backward substitution*)
x=Table[0,{i,n}] ;(*We create a list, in which we shall keep the values of the unknowns*)
For[i=n,i≥1, i--,
x[[i]]=((b[[i]]-Sum[A[[i,j]]x[[j]],{j,i+1,n}])/(A[[i,i]]))

];
x
)

Gauss[{{1,1,1},{5,2,2},{1,2,3}},{0,1,2}]

LinearSolve[{{1,1,1},{5,2,2},{1,2,3}},{0,1,2}]