phptutorials

PHP Script to print Prime Numbers!

In the previous post we saw how to find an Entered number is a Prime number or not!. In this post we are going to print all the Prime numbers.

If you don’t know what is a prime number, here is a small explanations:

  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)

Now, let’s see the script:

You can see the demo of the above script here:

demo

Thanks. Have a nice day!

Related Posts

One thought on “PHP Script to print Prime Numbers!

Leave a Reply