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

  1. Start, then read an integer n.
  2. If n is less than 2 it is not prime, so print not prime right away.
  3. Otherwise set i to 2.
  4. While i is less than n, check whether n mod i is 0. If it is, print not prime.
  5. If not, raise i by 1 and check again. If i reaches n with no exact division, print prime.

Good to know

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.

See the symbol rules

More examples