<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>Euclidean Algorithm</title>
</head>
<body>
<form method="get" action="EuclidAlgo.php">
<fieldset>
<label for="remainder">Euclidean Algorithm : </label>
<input type="text" name="NumberA" value="<?php echo (isset($_GET['NumberA'])) ? $_GET['NumberA'] : 5; ?>"/>
<input type="text" name="NumberB" value="<?php echo (isset($_GET['NumberB'])) ? $_GET['NumberB'] : 5; ?>"/>
<input type="submit" name='submit' value="submit" />
</fieldset>
</form>
<?php
function gcd($a, $b)
{
$a = abs($a);
$b = abs($b);
if ($a == 0)
{
return $b;
}
elseif ($b == 0)
{
return $a;
}
elseif ($a > $b)
{
return gcd($b, $a % $b);
}
else
{
return gcd($a, $b % $a);
}
}
function lcm($a, $b)
{
$a = abs($a);
$b = abs($b);
if ($a > $b)
{
return ($b / gcd($a, $b)) * $a;
}
else
{
return ($a / gcd($a, $b)) * $a;
}
}
if (isset($_GET['submit']))
{
$a = $_GET['NumberA'];
$b = $_GET['NumberB'];
} else {
$a = 5;
$b = 5;
}
echo gcd($a, $b);
?>
<br />
<?php
echo lcm($a, $b);
?>
My lcm function is not running correctly for example when i enter 100 and 150 into my program rather than it returning 50 it is returning 200 any ideas, also if i am missing anything important that i need to state just ask rather than complaining or giving my work a low mark.