function [B,C] = Exam2(A)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   Exam 2
%
%   This algorithm does something to a matrix.
%
%   Inputs:
%   1. A (nxn) matrix.
%
%   Ouputs:
%   1. B (nxn) matrix.
%   2. C (nxn) matrix.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Extracting information from A and allocating space for matries
[~,n]=size(A);
B=zeros(n,n);
C=zeros(n,n);

%% Main loop
for j=1:n,
    v=A(:,j);
    
    for i=1:j-1,
        v=B(:,i);
        aj=A(:,j);
        C(i,j)=v'*aj;
        v=v-C(i,j)*v;
    end

    B(:,j)=v/norm(v);
end