Prime number check

    Last updated November 30, 2026

    A prime number is an integer greater than 1 with no divisor other than 1 and itself. The chart tries divisors from 2 up to the square root of n. FlowSimp is completely free to use — no sign-up required.

    See the flowchart

    What does the flowchart look like?

    Ready to draw?

    No signup. Opens instantly in your browser.

    See the flowchart

    What is the matching code?

    Pseudocode

    read n
    if n < 2 then not prime
    i = 2
    while i * i <= n
      if n is divisible by i then not prime
      i = i + 1
    prime

    Python

    def is_prime(n):
        if n < 2:
            return False
        i = 2
        while i * i <= n:
            if n % i == 0:
                return False
            i += 1
        return True

    C

    int is_prime(int n) {
      int i;
      if (n < 2) return 0;
      for (i = 2; i * i <= n; i++) {
        if (n % i == 0) return 0;
      }
      return 1;
    }
    • 2 is prime: the bound 2 × 2 <= 2 is false, so the chart reports prime without testing a divisor.
    • 9 is not prime: i = 3 divides 9. 4 is not prime because 2 divides it.