A prime number is a number that can only be divided by itself and 1 without remainders. Here we explain what exactly this means, give you a list of the prime numbers children need to know at primary school and provide you with some practice prime number questions and examples.
What is a prime number?
A prime number is a number greater than 1 with only two factors – themselves and 1.
A prime number cannot be divided by any other numbers without leaving a remainder.
An example of a prime number is 13. It can only be divided by 1 and 13. Dividing a prime number by another number results in numbers left over e.g. 13 ÷ 6 = 2 remainder 1.
15 is not an example of a prime number because it can be divided by 5 and 3 as well as by itself and 1.
15 is an example of a composite number because it has more than two factors.
PHP Program for Check if a number is prime
<?php
// PHP code to check whether a number is prime or Not
// function to check the number is Prime or Not
function primeCheck($number){
if ($number == 1)
return 0;
for ($i = 2; $i <= $number/2; $i++){
if ($number % $i == 0)
return 0;
}
return 1;
}
// Driver Code
$number = 31;
$flag = primeCheck($number);
if ($flag == 1)
echo "Prime";
else
echo "Not Prime"
?>
No comments:
Post a Comment