Skip to main content

PHP program to list prime numbers

Here is the Program to list the first 15 prime numbers.

<?php 
$count = 0; 
$num = 2; 

while ($count < 15 ) 

{ 

$div_count=0; 

for ( $i=1; $i<=$num; $i++) 

{ 

if (($num%$i)==0) 

{ 

$div_count++; 

} 

} 

if ($div_count<3) 

{ 

echo $num." , "; 

$count=$count+1; 

} 

$num=$num+1;

} 
?> 

Comments

Popular posts from this blog

PHP program to convert word to digit

<?php function word_digit($word) {     $warr = explode(';',$word);     $result = '';     foreach($warr as $value){         switch(trim($value)){             case 'zero':                 $result .= '0';                 break;             case 'one':                 $result .= '1';                 break;             case 'two':                 $result .= '2'; ...

PHP Login and Logout example using sessions.

Program to create simple Login and Logout example using sessions. ✡️login.php  <html>  <head>  <title>Login Form</title>  </head>  <body>  <h2>Login Form</h2>  <form method="post"   action="checklogin.php"> User Id: <input type="text" name="uid"> <br> Password: <input type="password" name="pw"> <br> <input type="submit" value="Login"> </form> </body> </html> ✡️ checklogin.php  <?php  $uid = $_POST['uid'];  $pw = $_POST['pw']; if($uid == 'arun' and $pw == 'arun123') {  session_start(); $_SESSION['sid']=session_id();              header("location:securepage.php");  } ?> ✡️securepage.php  <?php session_start();  if($_SESSION['sid']==session_id())  {         echo "Welcome to you<br>";  ...