University of Illinois, Urbana-Champaign

**Topic: Prime algorithm
**** in pseudocode**

**February 4,
2016**

**Is 17 prime?**

**Since none of the divisions have a remainder of 0, it has no divisors between 1 and 17,**

**therefore 17 is a prime by the definition of a prime number.**

Pseudo-code for finding if a number is prime:

`
Input the number to be tested from the human user
Set a text variable called prime to "True"
Set divisor to 2
While the divisor is less than the number do the following loop
Use the modulo code to find the remainder
If the remainder is zero
Set prime to "False"
End If
divisor = divisor + 1
End of while loop
Output whether the number is prime or not (i.e., output the value in the variable prime)
`

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

`
Input number
prime <-- "True"
divisor <-- 2
While divisor < number
Comment: The following five lines are the algorithm to find the remainder of number divided by divisor
intermediate <-- number
While intermediate >= divisor
intermediate <-- intermediate - divisor
End While
remainder <-- intermediate
End of Comment
If remainder = 0
prime <-- "False"
End If
divisor = divisor + 1
End While
Output prime
`

University of Illinois, Urbana-Champaign