Php script or program to find square root of a given number

Simple program to find square root of a given number

<?php
$num=9;
$root=0;
$odd=1;
while($num>0)
{
$num-=$odd;
$root++;
$odd+=2;

}
echo $root;
?>

outputĀ 

3

Program to find square root of a given number using sqrt functions, classes and objects

<?php
class square
{
public $num=null;
public $objRes=null;
function processRequest()
{
$this->square=$_REQUEST[‘num’];
}

function run()
{
if(isset($_REQUEST[‘submit’]))
{
$this->processRequest();
$this->objRes=sqrt($this->square);

}
}
}
$objSquare=new square();
$objSquare->run();

?>
<html>
<center>
<h3>Square Root</h3>
<body>
<form action=”square.php” method=”POST”>
Enter the number:<input type=”text” name=”num”/>
<input type=”submit” name=”submit”/>
</form>
<?php
if($objSquare->res!=0)
echo “Square root of a given number is “.$objSquare->objRes.” “;
echo “<br>”;
?>
</body>
</center>
</html>

output