Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Write a program to check whether the number is prime or not.

<?php
$num = (int)readline('enter the number');
if($num%2 == 0) {
echo "num is the prime number";
}
else{
echo "the number is not prime";
}
?>

Output:
Write a program to print prime numbers between 1 to 100.
<?php
$num=1;
while($num <100){
$count=0;

for ($i=1;$i<=$num;$i++){
if(($num%$i)==0){
$count++;
}
}
if($count<3){
echo $num." , ";
}
$num=$num+1;
}
?>

Output:-
Write a program to calculate the factorial of any number .
<?php
function factorial($num){
if($num == 0){
return 1;
}
else if($num > 0){
return $num * factorial($num -1);
}
}
$fact;
// echo "enter the number ";
$fact = (int)readline('enter the number');
$factr = factorial($fact);
echo "factorial = ".$factr;

?>

Output:-
Write a program to generate the pyramids like:-

You might also like