Showing posts with label prime_number. Show all posts
Showing posts with label prime_number. Show all posts
23 October, 2018
How to Check Prime Number in Php
How to Check Prime Number in Php. Prime Number is the natural number which is divided by 1 and itself. So Today i am going to share a program with you in which you can check either a number is a prime number or not. For example 7 is the prime number which only divided by 1 and itself.
Program of Check Prime Number in Php
Programing Coderfunda
October 23, 2018
php, prime_number
No comments
How to Check Prime Number in Php
How to Check Prime Number in Php. Prime Number is the natural number which is divided by 1 and itself. So Today i am going to share a program with you in which you can check either a number is a prime number or not. For example 7 is the prime number which only divided by 1 and itself.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?php
function checkPrimeNumber($n){
for($i=2; $i<$n; $i++){
if($n%$i==0){
return false;
}else{
return true;
}
}
}
$a=checkPrimeNumber(11);
if($a) {
echo "Prime Number";
}else{
echo "Not a Prime Number";
}
?>
|