5. (B) Write a PHP program to accept a number from the user and print whether it is prime or not.

5. (B) Write a PHP program to accept a number from the user and print whether it is prime or not.

<html>
<head>
<h1>PRIME NUMBER</h1>
</head>
<body>
<form method="post"action="checkPrime.php">
Enter a Number:<input type="text"name="n1"><br>
<input type="submit"value="checkPrime">
</form>
</body>
</html>
checkPrime.php:
<?php
$n1=(int)$_POST['n1'];
$flag=0;
for($i=2;$i<=$n1/2;$i++)
{
if($n1%$i==0)
{
$flag=1;
break;
}
}
if($flag==0)
echo"Number is Prime";
else
echo"Number is not Prime";
?>
5. (B) Write a PHP program to accept a number from the user and print whether it is prime or not. 5. (B) Write a PHP program to accept a number from the user and print whether it is prime or not. Reviewed by admin on December 24, 2019 Rating: 5

No comments:

Powered by Blogger.