PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 31: Write a PHP program to print all prime numbers between 1 to 100.

prime_num.php

<!DOCTYPE html>
<html>
<head>	
	<title>PHP Programs TutorialDuniya.com</title>
</head>
<body>
	<?php  
		$count = 0;  
		$number = 0;  
		$i = 1;  
		$j = 1;

		echo "<br/>";
		echo "Prime numbers between 1 to 100 are  : ";  

		while($number < 25)  
		{  
			$j = 1;  
			$count=0;  
			while($j <= $i)  
			{  
				if($i%$j==0)  
				$count++;  
				$j++;   
			}  

			if($count == 2)  
			{
				echo $i;  
				echo " ";  
				$number ++;  
			}
			$i++;
		}
	?>
</body>
</html>



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.