Click New Example to start working through an example. Click on the steps of the algorithm to see the values of the variables in each step. First click on step 1. and then on the following steps in the order of execution.
New Example Restart Example
Division Algorithm for negative integers.
Input:a negative integer a and a natural number b
Output:Two integers q and r such that a=(q ⋅ b) + r and 0 ≤ r < b
  1. let q := 0
  2. let r := a
  3. repeat
    1. let q := q + 1
    2. let r := r + b
  4. until r ≥ 0
  5. return q,r