Write a php program to accept a number from the user and print whether it is prime or not

Write a php program to accept a number from the user and print whether it is prime or not. This script is helps you to find whether the number is prime or not. To print the number whether the number is prime number or not prime number in php programming language

 <?php 
$x = 0; 
$number = 2; 
while ($x < 10 ) 
{ 
$div_x=0; 
for ( $i=1; $i<=$number; $i++) 
{ 
if (($number%$i)==0) 
{ 
$div_x++; 
} 
} 
if ($div_x<3) 
{ 
echo $number." , "; 
$x=$x+1; 
} 
$number=$number+1; 
} 
?> 

 

Output:

2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29

What is prime number and which is smallest prime

A prime number is a whole number greater than one with the elements one and itself. A factor is a whole number that can be divided evenly into another number. Numbers with more than two components are called composite numbers. The definition of a prime number is a number that can only be divided by one and itself. A prime number cannot be divided by zero because integers split by zero are undefined. The smallest prime number is two, which is also the only even prime number.

How to find the prime number and why do we need

Positive integers with just two components, 1 and the integer itself, are known as prime numbers. Factors of six, for example, are 1,2,3, and six, for a total of four factors. However, there are only two components in the number seven: one and seven. As a result, whereas 7 is a prime number, 6 is not; it is a composite number. However, keep in mind that 1 is neither prime nor composite. The prime numbers are sometimes known as the numbers that are only divisible by one or the number itself. A positive number or integer that is not a product of any other two positive integers is another method of describing it. Apart from identifying its components, there is no method for determining whether a number is prime or not.