write the prime number of program?in php

Answers were Sorted based on User's Feedback



write the prime number of program?in php..

Answer / mishra ashutosh

i am assuming that you want to test whether a no is prime or not.

$no=123;//lets say, u can take this value form also using $_POST or $_GET
$flag=0;
for($i=2;$i<$no;++$i){
if($no%$i==0){
$flag=1;
break;
}
}
if($flag==1)
echo "$no is not a Prime No" ;
else
echo "$no is a Prime No" ;

Is This Answer Correct ?    18 Yes 1 No

write the prime number of program?in php..

Answer / akvh

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post">
Enter the number: <input type="text" name="num" />
<input type="submit" name="sub" />
</form>
<?php
if(isset ($_POST['sub']))
{
$a=$_POST['num'];
$i=2;
$f=0;

while($i<=($a/2))
{
if($a%$i==0)
{
$f=1;
break;
}

$i++;

}
if($f==1)
{
echo "NOT PRIME";
}
else
{
echo "PRIME";
}
}

?>
</body>
</html>

Is This Answer Correct ?    13 Yes 1 No

Post New Answer

More PHP Interview Questions

What library is used for pdf in php?

0 Answers  


Is strcmp case sensitive?

0 Answers  


What is Gd PHP?

0 Answers  


Explain php parameterized functions.

0 Answers  


What is difference between strstr() and stristr() in PHP?

0 Answers  






What is the difference between PHP,ASP and JSP?

3 Answers   T3 Softwares,


What are the different types of statements that are present in php?

0 Answers  


Write a PHP code to print following number pattern: 123 456 789

5 Answers  


How do you find the length of a string in php?

0 Answers  


What are the popular frameworks in php?

0 Answers  


Explain type casting and type juggling.

0 Answers  


Do you know what is the difference between mysql_fetch_object() and mysql_fetch_array()?

0 Answers  


Categories