Code:
<!DOCTYPE html><html>
<body>
<center>
<h1>First N Prime Numbers</h1>
<?php
if (isset($_POST['check']))
{
$status=1;
$num=3;
$n=$_POST['limit'];
if ($n>=1)
{
echo "2<br/>";
}
for ($i = 2; $i <= $n;)
{
for ($j = 2; $j <= sqrt($num) ; $j++)
{
if ($num%$j==0)
{
$status=0;
break;
}
}
if ($status!=0)
{
echo $num."<br/>";
$i++;
}
$status=1;
$num++;
}
}
?>
<form method="post" action="index.php">
Enter limit: <input type="text" name="limit">
<input type="submit" name="check" value="Check">
</form>
</center>
</body>
</html>
No comments:
Post a Comment