Code:
<!DOCTYPE html><html>
<body>
<center><h1>PRIME NUMBER OR NOT</h1>
<?php
if (isset($_POST['check']))
{
$k=$_POST['num'];
$flag=0;
$x=0;
for($i=2;$i<=$k;$i++)
{
for($j=2;$j<$i;$j++)
{
if($i%$j==0)
{
if ($i==$k) {
echo "$k is not a prime number";
}
$flag=1;
break;
}
}
if($flag==0)
{
if ($k==$i) {
echo "$k is a prime number";
break;
}
}
$flag=0;
}
}
?>
<form method="post" action="index.php">
Enter Number: <input type="text" name="num">
<input type="submit" name="check" value="Check">
</form>
</center>
</body>
</html>
No comments:
Post a Comment