Showing posts with label lcm in php. Show all posts
Showing posts with label lcm in php. Show all posts

Friday, February 20, 2015

Least Common Multiple (LCM) Number Finder in PHP

In this article I would like to share with you a basic math problem in finding least common multiple numbers using PHP as my programming language. Least Common Multiple numbers it refers to the smallest nonzero number that is a multiple of two or more numbers.

I hope you will find my work useful in learning how to write a program in PHP as your programming language.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Sample Output of Our Program


Program Listing

<html>
<title>LCM Number Finder</title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
 label{
    display: table-cell;
    text-align: justify;
}
input {
  display: table-cell;
}
div.row{
    display:table-row;
}
</style>
<?php
error_reporting(0);

$value1 = $_POST['val1'];
$value2 = $_POST['val2'];


$value1_one = (int)$value1;
$value2_two   = (int)$value2;

$temp1=$value1_one;
$temp2=$value2_two;
    while($temp1!=$temp2)
    {
        if($temp1>$temp2)
            $temp1-=$temp2;
        else
            $temp2-=$temp1;
    }

$solve =($value1_one*$value2_two)/$temp1;

if(isset($_POST['check'])) {
$title .= "<br>";
$title .= " ===== GENERATED RESULT ===== " ."<BR><BR>";
$title .= "The Least Common Multiple of Two Numbers "
       .$value1_one. " and ".$value2_two." is ".$solve.".<br><br>";
       
}
if(isset($_POST['clear'])) {
  $value1 = " ";
  $value2 = " ";
  $title= " ";
   
}
?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">  LCM Number Finder</h2>
 <form action="" method="post"><div>
  <div class="row"><label> Enter First Number  : </label> <input type="text" name="val1" 
           value="<?php echo $value1; ?>" autofocus required size=10/><br> </div>
<div class="row"> <label> Enter Second Number  : </label><input type="text" name="val2" 
           value="<?php echo $value2; ?>" required size=10/><br> </div>
  <br>
   <input type="submit" name="check" value="Find LCM Here" 
  title="Click here to find the least common multiple number."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>

<br> <br>

<?php 
echo $title;
 ?>
  </body>
</html>