Write a function to check whether a number is prime or not.
Note: A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
<?php function IsPrime($n) { for($x=2; $x<$n; $x++) { if($n %$x ==0) { return 0; } } return 1; } $a = IsPrime(3); if ($a==0) echo 'This is not a Prime Number.....'."\n"; else echo 'This is a Prime Number..'."\n"; ?>
Sample Output:
This is a Prime Number..
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer