Flowchart: check for a prime number
Divide n by every i from 2 up to n minus 1. If any division leaves no remainder, print not prime.
Steps
- Start, then read an integer n.
- If n is less than 2 it is not prime, so print not prime right away.
- Otherwise set i to 2.
- While i is less than n, check whether n mod i is 0. If it is, print not prime.
- If not, raise i by 1 and check again. If i reaches n with no exact division, print prime.
Good to know
- Looping i only up to the square root of n gives the same answer. This chart loops up to n minus 1 because it is easier to follow.
- If lines overlap where the two outputs join, move the nodes around in the text.
Drawing happens in this browser only. Your text is never sent to a server. Symbol rules differ a little between textbooks, so check them against your course before you hand in.