Deprecated: Function create_function() is deprecated in /home/ursaftwz/public_html/myscripthub.com/wp-content/plugins/codecolorer/lib/geshi.php on line 4698

Recursion,Prime Number in php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
function factorial($num)
{
if($num<2)
{
return 1;
}
else
{
return $num=$num*factorial($num-1);

}

}
echo factorial(5);
?>

<?php


function IsPrime($number)
{
if ($number < 2) {
return ('no prime');
}
for ($i=2; $i<=($number / 2); $i++) {
if($number % $i == 0) {
return ('no prime');
}
}
return ('prime');
}
echo IsPrime(35);

?>

2 Replies to “Recursion,Prime Number in php”

Leave a Reply