%divalg - compute quotient & remainder using only addition and subtraction.
% Maintains this equation as invariant:
%      dividend = quotient * divisor + remainder
% Upon termination, this equation holds and remainder is less than divisor.
dividend = input('Please input the dividend (positive integer): ');
divisor = input('Please input the divisor (positive integer): ');
quotient = 0;
remainder = dividend;
% (Invariant holds now)
while (remainder>=divisor)
    quotient=quotient+1;
    remainder=remainder-divisor;
end
% here the invariant holds, and 0 <= remainder < divisor
fprintf('The quotient is %d and the remainder is %d.',quotient,remainder);
fprintf('\n');
