Wednesday 25 February 2015

Remainder on division - the logic

In my previous post I described a method for calculating the remainder on dividing one integer by another. I now give the logic that can be used to solve this problem on a programmable calculator.

Store 1 in B
Store 0 in C
Store 10 in D
Input A
While D ≥ A
   Store D-A in D
WhileEnd
Label 1
Input X
If X=-1 then
   Goto Label 2
EndIf
While X ≥ A
   Store X-A in X
WhileEnd
Store C+BX in C
While C ≥ A
   Store C-A in C
WhileEnd
Store DB in B
While B ≥ A
   Store B-A in B
WhileEnd
Goto Label 1
Label 2
Display C

No comments:

Post a Comment