1

PHP Script to find Prime number or not!

Hello friends, Let’s see another School / College program that is useful for understanding the basic concepts of PHP.

And the PHP script what we are going to see is “Find the Prime numbers”.

If you already don’t know what is a Prime number, I will give you some example:

A prime number is a number that is divisible only by itself and 1.

For Eg:

  1. 1 is divisible by itself only (divisible by 1 natural number, so not a prime number)
  2. 2 is divisible by itself and also can be divisible by 1 (divisible by 2 natural numbers, so it a prime)
  3. 3 is also divisible by itself and by 1 (divisible by 2 natural numbers, so it a prime)
  4. But, 4 is divisible by itself as well as by 2 and by 1 (divisible by 3 natural numbers, so it is not a prime number)
  5. 5 is divisible by itself and by 1 (divisible by 2 natural numbers, so it is a prime number)
  6. 6 is divisible by itself and by 3 and by 2 and by 1 (so it is divisible by 4 natural numbers, so it is not a prime number)

Let’s see the scrip first:

You can read the comments in the above script to understand how the script works!

See the demo here:

demo

Adios!

agurchand

Technologist, software engineer, blogger with experience in Web development and the Media.

One Comment

Leave a Reply