Sunday, August 5, 2012

GCD and LCM of two numbers

Here is a Simple Program in Php which gives GCD and LCM of two Numbers.

   1) Here is a Simple Html Form to Enter the Two Numbers.

           <html>
<head>
<title>"LCMGCD"</title>
</head>
<body>
<form name="LCMGCD" method="GET" action="lcmgcd.php">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<fieldset>
  <ol>
      <li>
          <label>ENTER THE INTEGER NUMBER1:</label>
          <input type="text" name="Num1" value=" ">
      </li>
      <li>
          <label>ENTER THE INTEGER NUMBER2:</label>
          <input type="text" name="Num2" value=" ">
      </li>
      <li>   
        <input type="submit" name="LCMGCD" value="submit"><br>
      </li> 
</ol>
</fieldset>.
</td>
</tr>
</table>
</form>
</body>
</html>


2)  Here is lcmgcd.php for Calculating the two numbers.

        <?php
$n1=$_GET['Num1'];
$n2=$_GET['Num2'];
echo"FIRST NUMBER IS :-> $n1<br>";
echo"SECOND NUMBER IS :-> $n2<br>";
echo"GCD OF 2 NUMBERS IS :-> ".gcd($n1,$n2)."<br>";


function gcd($a,$b)
{
  $a1=$a;
  $b1=$b;
  while($a<>$b)
  {
     if($a>$b)
       $a=$a-$b;
     else
       $b=$b-$a;  
  }
  echo"<br>LCM OF 2 NUMBERS IS :-> ".(($a1*$b1)/$a)."<br>";
  return $a;

}
?>

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...