Off[General::spell1];
Clear[QRfact,a0];
QRfact[a0_] := 
Module[{a, b,n, m,k,c,beta,y,v,vvt,u}, 
 a = a0;
 mna = Dimensions[a];
 m = mna[[1]];  
 n = mna[[2]];
   norm[V_] :=N[ Sqrt[V.Conjugate[V]/.List->Plus], digit];
    b = Transpose[a];
    q = IdentityMatrix[m];
 Clear[i,k];
 For[k=1, k <= m-1, k++,
   c=Table[If[i >=k, b[[k,i]],0], {i,1,m}];(*k-th column*)
   beta =N[ -(b[[k,k]]/ Abs[b[[k,k]]]) norm[c],digit];
   y =  c - beta Table[If[i !=k,0,1], {i,1,m}];
   alpha = N[Sqrt[2] / norm[y],digit];
   v = alpha y;
   vvt= Table[v[[i]] Conjugate[v[[j]]],{i,m},{j,m}];
   u = IdentityMatrix[m]-vvt;  
   b = Simplify[b.Transpose[u]];
   q = u.q;   
 (*Print["U",k,"=" MatrixForm[Chop[u]]]; Print["    "];
    Print["Q",k,"=" MatrixForm[Chop[q]]]; Print["    "];
    Print["R",k,"=" MatrixForm[Chop[Transpose[b]]]];
   Print[ " "] *)
       (* The above bracket can be used to print out the
          intermediate steps *)   
    ];
a=Transpose[b];
Return[a]; ];
On[General::spell1];

digit = 8;

Clear[A];
A={{1,2},{1,1},{1,-1}};  
MatrixForm[A]

Clear[R];
R=QRfact[A];   
MatrixForm[Chop[R]]

Clear[Q];
Q=Transpose[q];
MatrixForm[Q]

MatrixForm[Q.R]

MatrixForm[Chop[Q.Transpose[Q]] ]

Clear[A];
A={{63,41,-88},{42,60,51},{0,-28,56},{126,82,-71}}; 
MatrixForm[A]

Clear[R];
R=QRfact[A]; 
MatrixForm[Chop[R]]

Clear[Q];
Q=Transpose[q];
MatrixForm[Q]

MatrixForm[Chop[Q.R] ]

MatrixForm[Chop[Q.Transpose[Q]]]

Clear[A];
A={{-1+I,2},{0, 1+I},{1-2I ,2} }; 
MatrixForm[A]

Clear[R];
R=QRfact[A]; 
MatrixForm[Chop[Simplify[R]]]

Clear[Q];
Q=Transpose[Conjugate[q]]; 
MatrixForm[Chop[Q]]

MatrixForm[Chop[Q.R]]

MatrixForm[Chop[Q. Transpose[Conjugate[Q]]] ]