University of Illinois, Urbana-Champaign

**Topic: Pseudocode
**** for the modulo algorithm**

**January 28,
2016**

The **modulo** operation is just the __remainder__ after the division, rather than the quotient:

Pseudo-code for calculating the modulo of two numbers:

`
input the number to be divided from the human user
input the divisor from the human user
set an intermediate variable to the number to be divided
while the intermediate is greater than or equal to the divisor do the following code in a loop
subtract the divisor from the intermediate and store the result back into the intermediate variable
end of while loop
set remainder equal to the intermediate
output the remainder to the user
`

Same pseudo-code written closer to a real computer language:

`
Input number
Input divisor
intermediate <-- number
While intermediate >= divisor
intermediate <-- intermediate - divisor
End While
remainder <-- intermediate
Output remainder
`

University of Illinois, Urbana-Champaign