function [R] = HW6_ArbDiv(A,B,N)
%ArbDiv Divides A/B and returns result to specified precision
% A/B must be less than ten and positive
%   INPUT
% A     Scalar or Nx1 Array
% B     Scalar
% N:    Number of desired digits
%   OUTPUT
% R:    Nx1 vector.  R(1).R(2)R(3) ......

R=zeros(N,1);

if isscalar(A) %We are creating an array by dividing two scalars
    
    %This is simply long division like we learn in grade school
    for ii=1:N
        R(ii)=floor(double(A)/double(B));
        A=(A-R(ii)*B)*10;
    end
    
else %We are dividing and existing array by a scalar
    
    %Approach here is to treat each element of the array as a scalar, and
    %use the above scalar calculation. Then add the results from each
    %scalar opereration. 
    
    %Division by each scalar.  Note the indexing to keep powers of 10
    %correct
    E=zeros(N,N);
    for nn=1:N
        E(nn:N,nn)=HW6_ArbDiv(A(nn),B,N-nn+1);
    end
    
    %Add up the results, two arrays at a time. 
    R=E(:,1);
    for nn=1:N-1
        R=HW6_ArbAdd(R,E(:,nn+1));
    end
    
end


end

